Int to bool, mvccheckboxfor of ASP. net mvc CheckBoxFor
When we use the CheckBoxFor type, we need to use bool to convert int to bool.
<Div class = "form-group"> <label class = "col-md-3 control-label"> options </label> <div class = "col-md-4"> @ Html. checkBoxFor (m => m. enabledValue) Valid @ Html. checkBoxFor (m => m. isUnfoldValue) Expand @ Html. checkBoxFor (m => m. allowEditValue) allows editing @ Html. checkBoxFor (m => m. allowDeleteValue) allows you to delete <span class = "help-block"> </span> </div>
Add purple code to the object class
/// <Summary> /// valid: 1-valid, 0-invalid // </summary> public int? Enabled {set {_ enabled = value;} get {return _ enabled;} public bool EnabledValue {get {return Enabled = 1;} set {Enabled = value? 1: 0 ;}}
Modify data
Public ActionResult Edit (string id) {ViewBag. controllerName = RouteData. values ["controller"]. toString (). toLower (); var model = new SAS. model. BPMS_SysMenu (); model = bll. getModel (id); if (model! = Null) {ParentDropDownList (); return View (model) ;}else {return View ("404") ;}} [HttpPost, ValidateInput (false)] public ActionResult Edit (string id, FormCollection fc) {var model = bll. getModel (id); if (model! = Null) {UpdateModel (model); // modify the data bll. Update (model); return RedirectToAction ("ModuleList");} else return View ("404 ");}
Inside the database
1-valid, 0-invalid
Good results