@Html.DropDownList

ViewBag.Producers = new SelectList(db.Producer, "ID", "TypeName");

1  @Html.DropDownList("Producers")       // edit 页面 有值  绑定上 默认选中  Producers字段的保存的数据

2  @Html.DropDownList("SpecialAptitude", EnumHelper.GetSelectList3(typeof(SpecialAptitude)), new { @class = "form-control", @onchange = "CheckType(this)" })     // 一个意思

 

public static IList<SelectListItem> GetSelectList3(Type enumType)
{
IList<SelectListItem> selectList = new List<SelectListItem>();

foreach (object e in Enum.GetValues(enumType))
{
selectList.Add(new SelectListItem { Text = GetEnumDescription(e), Value = ((int)e).ToString() });
}

return selectList;
}

posted @ 2017-11-30 17:08  ~雨落忧伤~  阅读(917)  评论(1编辑  收藏  举报