title: MVC 4 Custom template for bool (razor)
body: <p>I am using the twitter bootstrap framework, so to get the EditorFor and DisplayFor methods to output what I need, I created custom templates for each of the types like string, text, password etc.  For my login page I want a RememberMe bool, so as before, I created the following template and put in in Boolean.cshtml:</p>
  
  <pre><code>@model bool
  
  &lt;div class="control-group"&gt;
      &lt;div class="controls"&gt;
          &lt;label class="checkbox"&gt;
              @Html.CheckBoxFor(m =&gt; m, new {@class = "checkbox"})
              @Html.LabelFor(m =&gt; m)
          &lt;/label&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Pretty simple, but when I use:</p>
  
  <pre><code>@Html.EditorFor(m =&gt; m.RememberMe)
  </code></pre>
  
  <p>I get an exception saying the value being bassed cannot be null:</p>
  
  <pre><code>The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Boolean'.
  </code></pre>
  
  <p>What am I missing?  Seems like it should be straight forward.  The field on the model object looks like follows:</p>
  
  <pre><code>[Display(Name = "Remember me?")]
  public bool RememberMe { get; set; }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong> So it seems that in the end it's a matter of creating an empty view model object and passing it to the view instead of letting MVC create one on it's own.</p>