Hi @Shri-6058 ,
MVC - Checkbox list value not passed home controller with existing list
To this issue, you could refer the following sample:
Models:
public class TimeSheetViewModel
{
public string Name { get; set; }
public TimeSheet TimeSheet { get; set; }
}
public class TimeSheet
{
public string EmpNo { get; set; }
public List<TimeEntry> DayList { get; set; }
}
public class TimeEntry
{
public bool IsMealBreakWaived { get; set; }
public string TRAN_DATE { get; set; }
public bool IsMealBreakAllowed { get; set; }
}
Home Controller:
public IActionResult TimesheetIndex()
{
//test data
var item = new TimeSheetViewModel()
{
Name = "A",
TimeSheet = new TimeSheet()
{
EmpNo = "n101",
DayList = new List<TimeEntry>() {
new TimeEntry() { IsMealBreakWaived = true, IsMealBreakAllowed = false, TRAN_DATE = DateTime.Now.ToShortDateString() },
new TimeEntry() { IsMealBreakWaived = false, IsMealBreakAllowed = true, TRAN_DATE = DateTime.Now.AddDays(1).ToShortDateString() },
new TimeEntry() { IsMealBreakWaived = true, IsMealBreakAllowed = false, TRAN_DATE = DateTime.Now.AddDays(2).ToShortDateString() },
}
}
};
return View(item);
}
[HttpPost]
public IActionResult Calculate(TimeSheetViewModel model)
{
return Ok("success");
}
The TimesheetIndex.cshtml page: we can get the checkbox value from the IsMealBreakWaived property.
After running the application, the result is like this:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion