I have a table, and each row of the table has two checkboxes. I am going through each row of the table and trying to send a boolean back to the controller (true if checked, false if not), but the value being passed back is always false. For reference, this is how I have been setting up the table:
@foreach (var item in Model.lockers)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => item.IsActive, new { htmlAttributes = new { @class = "form-control IsEnabled" } })
</td>
<td>
@Html.CheckBoxFor(modelItem => item.IsADA, new { htmlAttributes = new { @class = "form-control IsADA" } })
</td>
</tr>
}
And this is my code to retrieve the information from this checkbox:
var list = [];
$('#tblMaster tbody tr').each(function (index, ele) {
var LockerDoorMaster = {
IsActive: $('.IsEnabled', this).is(":checked"),
IsADA: $('.IsADA', this).is(":checked")
}
list.push(LockerDoorMaster);
});
How can I modify my code so that the value 'true' will be passed back if the checkbox is checked? Thank you!
!!$('.IsEnabled', this).is(":checked"),This basically tells JavaScript if the value is '0' or 'null' than it's false else it's true.