Enum枚举转换为SelectListItem


private List<SelectListItem> _jobtitlelist;
public List<SelectListItem> JobTitle
{
get
{
_jobtitlelist = new List<SelectListItem>() { };
JobTitleEnum jobTitleEnum = JobTitleEnum.apprentice;
FieldInfo[] fieldinfo = jobTitleEnum.GetType().GetFields();
foreach (FieldInfo item in fieldinfo)
{
Object[] obj = item.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (obj != null && obj.Length != 0)
{
DescriptionAttribute des = (DescriptionAttribute)obj[0];
_list.Add(new SelectListItem() { Text = des.Description, Value = item.Name });
}
};
_list.Insert(0, new SelectListItem() { Value = "0", Text = "" });
return _jobtitlelist;
}
set { _jobtitlelist = value; }
}



posted @ 2018-05-25 15:29  莫小麦  阅读(1239)  评论(0编辑  收藏  举报