Alright ... Let's do it step by step ... because you haven't suggested a lot of data ... I'm going to make a script for you:
will say that you have this checkbox checked:
@Html.CheckBoxFor(model=>model.isValid,new {id="chkValid"})
Of course, ISValid is a bool variable.
One easy way:
@Html.CheckBoxFor(model=>model.isValid,new {@checked = "checked"})
Now, if for some reason this doesn’t work ... you can always go the old-fashioned way ... JQuery: ready in the document .. to do this:
$(document).ready(function () {
$('chkValid').attr('checked')= true;
});
Hope this helps
LAST EDIT: Good ... Try the following:@Html.CheckBoxFor(model=>model.isValid,new {id="chkValid" , onclick="updateChk("+@model.parameter+")"})
and this is the jquery function:
function updateChk(parameter)
{
if (($('#chkValid').is(':checked')) {
var check = true;
} else {
check = false;
}
$.ajax({
type: "POST",
url: '@Url.Action("Action", "Controller")',
data: "{parameter:parameter, status:'" + check + "'}",
contentType: "application/json; charset=utf-8",
success: function (data) {
}
});
}
- , !