Reputation: 907
I have a checkbox, is the case statement from the stored procedure marks the value as 1 I want to have the box checked. I tried this below but with no success.
<td width="2%">
@if (Model.IsCurrentlyClosed == true)
{
@Html.CheckBoxFor(item => checked(item.IsCurrentlyClosed))
}
else
{
@Html.CheckBoxFor(item => item.IsCurrentlyClosed)
}
Upvotes: 1
Views: 49
Reputation: 221
Please try this (for checked):
@Html.CheckBox("IsCurrentlyClosed")
Upvotes: 1
Reputation: 139
I didn't reproduce the behavior of the code, it's just an idea if you want to record the value:
$('#MyCheck').click(function () {
var check= new Object();
check.IsCurrentlyClosed= $(this).closest('tr').find(".CheckClass").val();
if (status != null) {
$.ajax({
type: "POST",
url: "/Home/EditPost",
data: JSON.stringify(check),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (this.checked)
alert('I m Checked');
else
alert('I m not Checked');
}
});
public JsonResult EditPost(DataBase CheckData)
{
DataBase check= new DataBase()
{
IsCurrentlyClosed= CheckData.IsCurrentlyClosed,
};
db.Entry(check).State = EntityState.Modified;
db.SaveChanges();
return Json(check, JsonRequestBehavior.AllowGet);
}
Upvotes: 0