0

如何使用 MVC 将 2 个单选按钮绑定到单个模型属性@Html.RadioButtonFor()

4

1 回答 1

0

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>
于 2012-06-04T16:20:45.977 回答