【发布时间】:2013-08-15 08:03:03
【问题描述】:
如何将枚举绑定到 MVC 中的下拉列表中,以使模型在发布后有效? 不确定它是否需要转换器或其他东西,我提供了代码,您推荐的解决方案是什么? (以下代码导致 ModelError)
枚举:
public enum TimePlan
{ Routine = 0,
Single = 1 }
模型:
public TimePlan TheTimePlan { get; set; }
public SelectListItem[] TimeList { get; set; }
控制器:
[HttpPost]
public virtual ActionResult Education(EducationViewModel EducationModelInfo)
{
if (ModelState.IsValid)
{ ...
} }
视图绑定:
@Html.DropDownListFor(m => m.CourseTimePlan, Model.TimeList, "Please select the time plan")
【问题讨论】:
标签: asp.net-mvc enums type-conversion model-binding