在局部视图 我的工作与这样的文本框。
@model字典<字符串,字符串>
@ Html.TextBox(XYZ,@Model [XYZ])
我怎么能产生单选按钮,并获得形式收集所需的值是/否真/假)?目前,我得到空的ABC如果我选择以下任意值。
<标签> @ Html.RadioButton(ABC,@Model [ABC])是< /标签>
<标签> @ Html.RadioButton(ABC,@Model [ABC])否LT; /标签>
控制器
公众诠释创建(INT编号,字典<字符串,字符串> formValues)
{
//有东西
}
解决方案
为了做到这一点为多个项目做这样的事情:
的foreach(在模型的VaR项)
{
@ Html.RadioButtonFor(M => m.item,是)@:是
@ Html.RadioButtonFor(M => m.item,否)@:无
}
In partial view I work with textboxes like this.
@model Dictionary<string, string>
@Html.TextBox("XYZ", @Model["XYZ"])
How can i generate radiobuttons, and get the desired value in the form collection as YES/NO True/False) ? Currently i am getting null for "ABC" if i select any value for the below.
<label>@Html.RadioButton("ABC", @Model["ABC"])Yes</label>
<label>@Html.RadioButton("ABC", @Model["ABC"])No</label>
Controller
public int Create(int Id, Dictionary<string, string> formValues)
{
//Something Something
}
解决方案
In order to do this for multiple items do something like:
foreach (var item in Model)
{
@Html.RadioButtonFor(m => m.item, "Yes") @:Yes
@Html.RadioButtonFor(m => m.item, "No") @:No
}