I use the twitter bootstrap framework, so in order to get the EditorFor and DisplayFor methods to display what I need, I created custom templates for each of the types, such as string, text, password, etc. For my login page, I need the RememberMe bool function, as before, I created the following template and entered it in Boolean.cshtml:
@model bool <div class="control-group"> <div class="controls"> <label class="checkbox"> @Html.CheckBoxFor(m => m, new {@class = "checkbox"}) @Html.LabelFor(m => m) </label> </div> </div>
Pretty simple, but when I use:
@Html.EditorFor(m => m.RememberMe)
I get an exception saying that the value based on the bass cannot be null:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Boolean'.
What am I missing? Looks like it should be straight. The field of the model object is as follows:
[Display(Name = "Remember me?")] public bool RememberMe { get; set; }
Thank.
UPDATE:. It seems that ultimately it is a matter of creating an empty view model object and passing it to the view instead of letting MVC create it on its own.
Tyrel Van Niekerk Jan 20 '13 at 15:22 2013-01-20 15:22
source share