后台:
public enum Shop_State
{
仓库中,
销售中,
已下架
}
public ActionResult Index()
{
List<string> list = new List<string>();
foreach(Shop_State str in Enum.GetValues(typeof(Shop_State)))
{
list.Add(str.ToString());
}
ViewBag.list = list;
//ViewBag.list = Enum.GetValues(typeof(Shop_State)).Cast<Shop_State>();
return View();
}
前台代码:
1 直接绑定下拉:
@Html.DropDownList("enumList", new SelectList(ViewBag.list), new { @class = "btn btn-success dropdown-toggle form-control" })
2循环绑定html控件:
@foreach (var item in (List<String>)ViewBag.list)
{
<input type="radio" value="@item" />@item
}