@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;
}