title: How can I make Html.CheckBoxFor() work on a string field?
body: <p>I'm using ASP.NET MVC3 with Razor and C#. I am making a form builder of sorts, so I have a model that has a collection of the following object:</p>
  
  <pre><code>public class MyFormField
  {
      public string Name { get; set; }
      public string Value { get; set; }
      public MyFormType Type { get; set; }
  }
  </code></pre>
  
  <p>MyFormType is just an enum that tells me if the form field is a checkbox, or textbox, or file upload, or whatever.  My editor template looks something like this (see the comment):</p>
  
  <p><em>~/Views/EditorTemplates/MyFormField.cshtml</em></p>
  
  <pre><code>@model MyFormField
  @{
      switch (Model.Type)
      {
          case MyFormType.Textbox:
              @Html.TextBoxFor(m =&gt; m.Value)
          case MyFormType.Checkbox:
              @Html.CheckBoxFor(m =&gt; m.Value)  // This does not work!
      }
  }
  </code></pre>
  
  <p>I tried casting/converting the <code>m.Value</code> to a bool in the lambda expression for CheckBoxFor(), but that threw an error.  I would just manually construct a checkbox input, but CheckBoxFor() seems to do two things that I can't seem to replicate: </p>
  
  <ol>
  <li>Creates a hidden input that somehow gets populated by the checkbox.  This appears to be what the model binder picks up.</li>
  <li>Generates the name form the object so that the model binder gets the value into the right property.</li>
  </ol>
  
  <p><strong>Does anyone know a way around using CheckBoxFor() on a string, or a way to replicate its functionality manually, so that I can make this work?</strong></p>