title: MVC3 EditorTemplate for a nullable boolean using RadioButtons
body: <p>I have a property on one of my objects that is a nullable boolean, I want my logic to have true represent Yes, false to be No and null to be N/A. Now because I am going to have multiple properties like this on many different objects it makes the most sense to make an editor and display templates for these properties. I am going to use jQuery UI to apply a visual element of buttonset after this is all working but for now, that's beyond the scope of my problem. My editor template looks like this.</p>
  
  <pre><code>@model bool?
  &lt;div data-ui="buttonset"&gt;
  @Html.RadioButtonFor(x =&gt; x, true, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("") + "Yes"}) &lt;label for="@(ViewData.TemplateInfo.GetFullHtmlFieldId(""))Yes"&gt;Yes&lt;/label&gt;
  @Html.RadioButtonFor(x =&gt; x, false, new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("") + "No" }) &lt;label for="@(ViewData.TemplateInfo.GetFullHtmlFieldId(""))No"&gt;No&lt;/label&gt;
  @Html.RadioButtonFor(x =&gt; x, "null", new { id = ViewData.TemplateInfo.GetFullHtmlFieldId("") + "NA" }) &lt;label for="@(ViewData.TemplateInfo.GetFullHtmlFieldId(""))NA"&gt;N/A&lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My problem is that under no circumstances can I get this editor template to show the current value of the model correctly. Because I am not rendering a property of a model at this scope but the model itself, the built in logic in MVC3 will not set the checked property correctly because of a check that is made to verify the name is not empty or null (See MVC3 source, InputExtensions.cs:line#259). I can't set the checked attribute dynamically by comparing to the Model because the browser checks the radiobutton on the presence of the checked attribute not it's value, so even though my radio buttons would look like the following the last one is still the one selected.</p>
  
  <pre><code>&lt;div class="span-4" data-ui="buttonset"&gt;
  &lt;input checked="checked" id="MyObject_BooleanValueYes" name="MyObject.BooleanValue" type="radio" value="True" /&gt;&lt;label for="MyObject_BooleanValueYes"&gt;Yes&lt;/label&gt;
  &lt;input checked="" id="MyObject_BooleanValueNo" name="MyObject.BooleanValue" type="radio" value="False" /&gt;&lt;label for="MyObject_BooleanValueNo"&gt;No&lt;/label&gt;
  &lt;input checked="" id="MyObject_BooleanValueNA" name="MyObject.BooleanValue" type="radio" value="null" /&gt;&lt;label for="MyObject_BooleanValueNA"&gt;N/A&lt;/label&gt;
  &lt;/div&gt;&lt;span class="field-validation-valid" data-valmsg-for="MyObject.BooleanValue" data-valmsg-replace="true"&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
  </code></pre>
  
  <p>I can't conditionally add the HtmlAttribute using something like <code>if?truevalue:falsevalue</code> becuase the true/false parts would be of different anonymous types and I get an error.</p>
  
  <p>I'm struggling on how this should be done and am hoping one of you have a suggestion on how to tackle this problem?</p>