Bind radio button to single model preoperty in MVC3

2.2k views Asked by At

How do you bind 2 radio buttons to a single model property in MVC using @Html.RadioButtonFor()

1

There are 1 answers

0
danludwig On BEST ANSWER

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>