Use Html.RadioButtonFor and Html.LabelFor for the same Model but different values

Don’t over-engineer a solution for this. All you are trying to accomplish is to have the radio buttons respond to clicks on the text. Keep it simple and just wrap your radio buttons in label tags:

<table>
<tr>
    <td><label>@Html.RadioButtonFor(i => i.Value, "1")True</label></td>
</tr>
<tr>
    <td><label>@Html.RadioButtonFor(i => i.Value, "0")False</label></td>
</tr>
</table>

The LabelFor html helper is usually used to bring in the Name from the Display attribute on your View Model (e.g. “[Display(Name = “Enter your Name”)]).

With radio buttons, the name isn’t particularly useful, because you have a different line of text for each radio button, meaning you are stuck hard coding the text into your view anyway.

Leave a Comment