我有三个单选按钮,但是当我选择EFG并将其发布到控制器时,我总是在Selected属性中获得ABC。
查看
@Html.RadioButtonFor(m => m.Selected, AllEnum.ABC) <label>ABC</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.EFG)<label>EFG</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.QWE)<label>QWE</label>
型号
public AllEnum Selected{ get; set; }
您能帮助我在控制器中获取选定的单选按钮值吗?
答案 0 :(得分:0)
下面是工作代码。
模型
public enum AllEnum
{
ABC,
EFG,
QWE
}
public class SimpleModel
{
public AllEnum Selected { get; set; }
}
控制器
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
var model = new SimpleModel();
return View(model);
}
[HttpPost]
public ActionResult Index(SimpleModel model)
{
return View(model);
}
}
查看
@using SimpleMVC.Models
@model SimpleMVC.Models.SimpleModel
@using (Html.BeginForm())
{
@Html.RadioButtonFor(m => m.Selected, AllEnum.ABC) <label>ABC</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.EFG)<label>EFG</label>
@Html.RadioButtonFor(m => m.Selected, AllEnum.QWE)<label>QWE</label>
<input type="submit" />
}