1

Currently I am storing my radio button as a bool

Nullable<bool> HasConnector {get; set;}

In the view I have three radio buttons true false and I check the third for null and then display the radiobutton as checked if it is null.

            @if(Model.PdsToEdit.HasConnector.HasValue)
            {
            @Html.RadioButtonFor(model => model.PdsToEdit.HasConnector, string.Empty)
            }else
            {
             @Html.RadioButtonFor(model => model.PdsToEdit.HasrConnector, string.Empty, new { Checked= "checked"})   
            }

How could I simplify this is there any data annotation in MVC5 for null bools so I can keep my view clean?

Bob
  • 1,065
  • 2
  • 16
  • 36
  • Try the following http://stackoverflow.com/questions/6752013/mvc3-editortemplate-for-a-nullable-boolean-using-radiobuttons – Marko Nov 22 '13 at 21:16
  • Thanks, I saw that already though, not a very elegant addition. – Bob Nov 22 '13 at 21:25

0 Answers0