I'm trying to render a radiobutton with some boolean attributes (required and disabled) using:
@Html.RadioButton("radio-name","false", new { id="test", required=Model.BooleanValue})
and
<input type="radio" name="radio-name" id="radio-name-no" value="false" class="radio" @if (!Model.BooleanValue) { <text>required</text> } disabled="@Model.BooleanValue" />
But the output is this:
<input id="test" name="radio-name" required="False" value="false" type="radio">
and
<input name="radio-name" id="radio-name-no" value="false" class="radio" disabled="True" type="radio">
MVC4 should render the boolean attributes as per HTML5 specs, so why it's outputting disabled="True" (or False) instead of disabled="disabled" or disabled (or nothing at all if the BooleanValue property is false)?
disabled="@Model.BooleanValue"- but what are you wanting to do here.disabled="true"anddisabled="false"(ordisabled="disabled"or justdisabled) are all identical - its the presence of the attribute which determines if its disabled or not. You need to conditionally add the attribute.disabled(ordisabled=disabled) instead ofdisabled="True", and don't render it at all if the Model's property is false or null. It seems like in my case it does a ToString() and directly assigning the boolean's value to the attribute.htmlAttributesusingnew { ... }(conditional attributes do not apply then). And the 2nd case does work and will generatedisabled="disabled" if the property istrue` and omit it iffalse- I can only assume your not using Razor2