MVC Html.Checkbox

MVC Html.Checkbox

我有一个复选框,存储过程中的 case 语句将值标记为 1 我想选中该复选框。我在下面尝试过但没有成功。

<td width="2%">
    @if (Model.IsCurrentlyClosed == true)
    {
        @Html.CheckBoxFor(item => checked(item.IsCurrentlyClosed))
    }
    else
    {
        @Html.CheckBoxFor(item => item.IsCurrentlyClosed)
    }

请试试这个(选中):

@Html.CheckBox("IsCurrentlyClosed")

我没有重现代码的行为,如果你想记录值,这只是一个想法:

$('#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);
    }