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?
?
答案 0 :(得分:-1)
@Html.CheckBoxFor(m => m.isAdministrator.Value)
And be sure to check that it has value before or you'll get exception.
However, using nullable in view model is not a best practice.