I have a weird issue, I check a checkbox, then if I return the same view then my checked checkboxes remain checked. But if I go to uncheck them, it checks them again. Then after that the behavoir is back to normal, I can uncheck them and recheck them etc. But it means I have to double click to uncheck already checked checkboxes after a page refresh.
I have checked via chrome debugger and in my controller that they are infact checked before and after the first click of the checkbox.
<td>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary checkboxes">
<span class="glyphicon glyphicon-unchecked large-glyphicon"></span>
- @Html.CheckBoxFor(m => m.Equipment[i].Checked, new {@class= "assetCheckBox" })
@Model.Equipment[i].AsssetNumber
</label>
</div>
</td>
My model has a list of equipment objects which all have the field
public bool Checked { get; set; }
And my controller
public ActionResult UpdatStatus(EquipmentSearch search)
{
_repository.Search = search;
var userActionResult = Services.EsignSecurity.Esign(search.Username, search.Password, _repository.SaveEquipmentChanges);
ShowResultInModal(userActionResult.Success, userActionResult.ReturnMessage);
return View("Index", GetMatchingEquipment(search.SearchType, search.SearchInput));
}
My script:
$(document).ready(function () {
BindPageLoadEvents();
});
function BindPageLoadEvents() {
$(function() {
$(".assetCheckBox").change(function() {
if ($(this).prop("checked")) {
activateEsign($(this).parent());
$(this).prev().addClass("glyphicon-ok-circle");
$(this).prev().removeClass("glyphicon-unchecked");
} else {
deactivateEsign($(this).parent());
$(this).prev().removeClass("glyphicon-ok-circle");
$(this).prev().addClass("glyphicon-unchecked");
}
});
});
}
function ifNothingCheckedDisableEsignActions() {
// ReSharper disable once CssBrowserCompatibility
if ($("#tblEquipment input:checkbox:checked").length > 0) {
$("#pnlEsignActions").find("*").removeAttr("disabled");
} else {
$("#pnlEsignActions").find("*").attr("disabled", true);
}
}
function activateEsign(element) {
$(element).removeClass("btn-primary");
$(element).addClass("btn-warning");
}
function deactivateEsign(element) {
$(element).removeClass("btn-warning");
$(element).addClass("btn-primary");
}
EDIT: I've added more code that the checkbox is nested in as I think that may what's causing the issue. Would greatly appreciate any thoughts.