Problem while updating a child list in C # ASP.Net MVC

Refresh

2 weeks ago

Views

7 time

0
public class PayRateDaysModel.   
{
    public string day_name { get; set; }
    public List<RateList> multiplier { get; set; }
}
public class RateList
{
    public double start_after { get; set; }
    public double rate_multiplier { get; set; }
}

when I'm trying to update any value in multiplier of PayRateDaysModel then its updating all multiplier values of PayRateDaysModel. I want to update only current item.

Below is my code :

var dayExists = daysModel.Where(x => x.day_name == day_name).FirstOrDefault();
    if(dayExists==null)
    {
           PayRateDaysModel days = new PayRateDaysModel();
           days.day_name = day_name;
           days.multiplier = rate_list;
           daysModel.Add(days);
    }
    else
    {
           //update
             dayExists.day_name = "abc";               
          dayExists.multiplier.FirstOrDefaulttt().rate_multiplier = 1;

}

0 answers