Asp.net mvc 3 将单选按钮绑定到MVC3中的单个模型属性
如何在MVC中使用模型中的Asp.net mvc 3 将单选按钮绑定到MVC3中的单个模型属性,asp.net-mvc-3,radiobuttonfor,Asp.net Mvc 3,Radiobuttonfor,如何在MVC中使用模型中的@Html.radiobutton()将两个单选按钮绑定到单个模型属性: public class MyModel { public bool? DoYouAgree { get; set; } } 在你看来: <label> @Html.RadioButtonFor(m => m.DoYouAgree, false, new { id = "DoYouAgree_false" }) No </labe
@Html.radiobutton()
将两个单选按钮绑定到单个模型属性:
public class MyModel
{
public bool? DoYouAgree { get; set; }
}
在你看来:
<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>
@Html.RadioButtonFor(m=>m.DoYouAgree,false,
新建{id=“DoYouAgree\u false”})
不
@(m=>m.DoYouAgree,true,
新建{id=“DoYouAgree\u true”})
对
读取第一个答案可能重复。我仍然无法理解正确的值是如何到达模型属性的。它们应该具有相同的名称。如果编写RadioButton,则应为两个RadioButton传递参数htmlattribute new{name=“a”}。最好使用radiobutton而不是radiobutton