I have a radiobutton code - timesheet.cshtml
//Jquery/Javascript
$(function () {
if ($("input[name=SelectedAttestation]:checked").val() == 2) {
$('#breaks-not-taken-section').show();
}
$("input[name=SelectedAttestation]").change(function () {
if ($(this).val() == 2) {
$('#breaks-not-taken-section').show();
}
else {
$('#breaks-not-taken-section').hide();
}
});
}
$.post("/Home/Calculate", $("form").serialize(), function (json) {
//alert("Success");
});
HomeController.cs -
This is for onload form functionalities and if there are any records in the database, it defaults the radio button selected the 1st option if no record exist in db. If data Exist, it selects the radio button and list out the “#breaks-not-taken-section'” div with all worked/7 days where they have checked for certain/all days.
[HttpGet]
public ActionResult TimeSheet(string p, string tz) //p- person EmpNo. tz-timezone
{
var mealAndRestTimes = CustomService.GetEntriesFromCustomDb(User.EmployeeNo, DateTime.Parse(pt[0]), DateTime.Parse(pt[1]));
int attncheck = 0; var curlength = mealAndRestTimes.Length;
if (curlength != 0)
{
for (int ctr = 0; ctr < curlength; ctr++)
{
foreach (var day in timeSheet.DayList)
{
if ((mealAndRestTimes[ctr].RestHours > 0) && (day.TRAN_DATE == mealAndRestTimes[ctr].Date))
{
day.IsRestBreakMissed = true;
attncheck = 1;
}
if ((mealAndRestTimes[ctr].RestHours == 0) && (day.TRAN_DATE == mealAndRestTimes[ctr].Date))
{
day.IsRestBreakMissed = false;
}
}
}
}
}
if (attncheck != 0)
{
model.SelectedAttestation = 2;
}
else if (attncheck == 0)
{
model.SelectedAttestation = 1;
}
return View(model);
}
[HttpPost]
// [ValidateAntiForgeryToken]
public ActionResult Calculate(TimeSheetViewModel model, FormCollection form)
{
model.TimeSheet.Emp_Uno = User.EmpNo;
var testRadio = model.SelectedAttestation.Value;
var formRadio = form["SelectedAttestation"];
}