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>)

 

posted on 2019-10-07 11:53  平凡滴人  阅读(159)  评论(0编辑  收藏  举报