I have a checkbox populated based on the List “DayList”, in Timesheet.cshtml
@if (Model.TimeSheet.DayList != null)
{
for (var i = 0; i < Model.TimeSheet.DayList.Count(); i++)
{
@Html.HiddenFor(x => Model.TimeSheet.DayList[i].IsMealBreakAllowed)
<div class="checkbox">
<label>@Html.CheckBoxFor(m => Model.TimeSheet.DayList[i].IsMealBreakWaived, new {
@class = "missed" })
@Html.FormatDayOfTheWeek(Model.TimeSheet.DayList[i].TRAN_DATE)
@Html.HiddenFor(x => Model.TimeSheet.DayList[i].TRAN_DATE)
</label>
</div>
}
}
On clicking the checkbox(es), I want to perform postback and refresh full page after calculations and it goes to Homecontroller
$(".missed").click(function () {
$.post("/Home/Calculate", $("form").serialize(), function (json) {
TODO - perform a page refresh/postpack
});
});
POSTBack home ActionControl:
public ActionResult Calculate(TimeSheetViewModel model)
{
model.TimeSheet.EmpNo = User.EmpNo;
//var week = _payRollService.ExecutePayRollRules("", null, null); // TODO
foreach (var day in timeSheet.DayList)
{
If(day.IsMealBreakAllowed) // It always return false and even if I checked checkbox,
//it shows false. How can I ensure that the checkbox value
//true when checkbox is checked
{
PayRollService.AddTimeEntries(model.TimeSheet);
}
return View("TimeSheet", model);
}
I have a _PayrollService model called “TimeEntry.cs” has the
public bool IsMealBreakWaived { get; set; }
Do I have to have a separate property in the TimesheetView Model as well?
Please advise.




