[英]Getting first enum as always selected from radiobutton
我有三个单选按钮,但是当我选择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; }
您能帮助我在控制器中获取选定的单选按钮值吗?
以下是工作代码。
模型
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" />
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.