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 h
You can use a @helper to simplify the accepted answer:
@model bool?
@Radio(true, "Yes", "Yes")
@Radio(false, "No", "No")
@Radio(null, "N/A", "NA")
@helper Radio(bool? buttonValue, string buttonLabel, string buttonId)
{
Dictionary attrs = new Dictionary();
// Unique button id
string id = ViewData.TemplateInfo.GetFullHtmlFieldId("") + buttonId;
attrs.Add("id", id);
// Check the active button
if (Model == buttonValue)
{
attrs.Add("checked", "checked");
}
@Html.RadioButtonFor(m => m, buttonValue, attrs)
}