Bind radio button to single model preoperty in MVC3
-
12-06-2021 - |
Question
How do you bind 2 radio buttons to a single model property in MVC using @Html.RadioButtonFor()
Solution
In your model:
public class MyModel
{
public bool? DoYouAgree { get; set; }
}
In your view:
<label>
@Html.RadioButtonFor(m => m.DoYouAgree, false,
new { id = "DoYouAgree_false" })
No
</label>
<label>
@Html.RadioButtonFor(m => m.DoYouAgree, true,
new { id = "DoYouAgree_true" })
Yes
</label>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow