我正在工作MVC4
。在此我使用以下代码radio buttons
:
模型 :
public class PlatInspHistoryModels
{
public List<RadioButtonItem> RadioButtonList { get; set; }
public string SelectedRadioButton { get; set; }
}
public class RadioButtonItem
{
public string Name { get; set; }
public bool Selected { get; set; }
public string Value { get; set; }
public bool Visible { get; set; }
}
控制器 :
public ActionResult Index()
{
var viewModel = new PlatInspHistoryModels
{
RadioButtonList = new List<RadioButtonItem>
{
new RadioButtonItem
{
Name = "Topside", Value = "T",Selected = true,Visible = true
},
new RadioButtonItem
{
Name="Underwater", Value = "U",Selected = false,Visible = true
}
}
};
return View(viewModel);
}
看法 :
@using (Html.BeginForm("Index", "PlatInspHistory", FormMethod.Post, new { id = "form" }))
{
<table cellpadding="4" cellspacing="4">
<tr>
<td>
foreach (Cairs2.Models.RadioButtonItem item in Model.RadioButtonList)
{
@Html.DisplayFor(i => item.Name)
@Html.RadioButton("PlatInspHistoryModels.SelectedRadioButton", item.Value, item.Selected, new { @class = "formCheckbox", tabindex = "1" })
}
</td>
</tr>
</table>
}
问题 :
从上面的代码中,我可以将单选按钮绑定为列表。但是我如何在save event
下面给出选定的无线电值:
[HttpPost]
public ActionResult Index(PlatInspHistoryModels model)
{
}