c# - 始终从单选按钮中选择第一个枚举
问题描述
我有三个单选按钮,但是当我选择 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" />
}
推荐阅读
- python - ggplot Python:错误:TypeError:“模块”对象不可调用
- mobile - Error running Flutter App
- java - Custom Camera not saving the whole image
- r - Error "could not find function nnet" in R
- python - super(A,cls).__new__(cls) 创建基类的实例吗?
- pypi - 如何在 pypi 上传中指定上传服务器?
- laravel - Laravel 响应良好实践
- c++ - 我如何正确地将 dlsym 的返回值转换为具有 const 类型的函数?
- php - PHPExcel:excel表格下载但内容不显示
- splunk - Splunk - 在维护窗口期间禁用警报