I am attempting to retrieve the bool value from the CheckBox and assign it to the variable m.IsAdministrator, which is of type bool?:
@Html.CheckBoxFor(m => (bool?)(m.isAdministrator))
However, this syntax gives an error. How can I assign the bool CheckBoxFor return value to a bool??
bool?tobool" from the MVC framework when it tries to compile the view, because it expects<Expression<Func<TModel,bool>>>but finds<Expression<Func<TModel,bool?>>>.boolfrom abool?, where you want the default value to befalseif thebool?isnull, then you would use the.Valueproperty if.HasValueistrue, otherwise usefalse. You can do this with the?:ternary operatory:bool x = m.isAdministrator.HasValue ? m.isAdministrator.Value : false;bool?has 3 states (true,nullandfalse). A checkbox has only 2 therefore you cannot use a checkbox for abool?Either make the propertyboolor useEditorFor(m =>m.isAdministrator)which willl generate a dropdownlist with 3 values