zl程序教程

您现在的位置是:首页 >  前端

当前栏目

@Html.DropDownList

HTML DropDownList
2023-09-11 14:14:40 时间

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