1

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)
    }
1
  • you intend to save the check status in the database? Commented Mar 1, 2021 at 17:37

2 Answers 2

1

Please try this (for checked):

@Html.CheckBox("IsCurrentlyClosed")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @BassemAdas the first option brings everything back as checked. I only want the checkboxes checked based on the flag set in the proc. The second option did not work
@AndyWilliams Sorry for the confusion, I edited the answer, I think it works fine now.
0

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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.