mardi 18 octobre 2016

How to preserve checkbox checked status in MVC4

I am developing MVC4 application and I have paging. I have one checkbox in the page. I am using paging so i want to preserve the values of all fields. I am using Models and viewbag to preserve the values for textbox and dropdownlist. I am finding difficuties with checkbox to preserve the value.

For example, dropdownbox is as follows,

@Html.DropDownListFor(x => x.doc_typeid, Model.doctype_name, "Select", new { @class = "form-control" })

For example, Textbox is as follows,

       @Html.TextBoxFor(x => x.employeeID, Model.employeeID, new { @id = "employeeID", @placeholder = "Employee ID", @class = "form-control text-input", @maxlength = 20 })

This is my checkbox.
 @for (int i = 0; i < Model.EmploymentType.Count; i++)
                                        {
                                            @Html.CheckBoxFor(m => m.EmploymentType[i].isChecked, new { id = "employmentType_" + i })
                                            @Html.HiddenFor(m => m.EmploymentType[i].checkBoxName)
                                            @Html.DisplayFor(m => m.EmploymentType[i].checkBoxName)
                                        }

Here I am not sure how to preserve the checkbox checked value? Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire