MVC视图中把枚举转成DropdownList
作者:互联网
1.控制器使用Linq生成ViewBag
ViewBag.DropDownList = Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>().Select(e => new SelectListItem { Value = ((int)e).ToString(), Text = e.ToString() });
2.视图绑定
@Html.DropDownListFor(m => m.value, ViewBag.DropDownList as IEnumerable<SelectListItem>)
标签:ViewBag,视图,Html,int,MVC,ToString,DropdownList,DropDownList 来源: https://www.cnblogs.com/zhm001/p/11629927.html