Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 将单选按钮绑定到MVC3中的单个模型属性_Asp.net Mvc 3_Radiobuttonfor - Fatal编程技术网

Asp.net mvc 3 将单选按钮绑定到MVC3中的单个模型属性

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

如何在MVC中使用模型中的
@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