public static List<SelectListItem> GetSelectItemList<T>(string textDefault,string valueDefault="") { List<SelectListItem> list = new List<SelectListItem>(); list.Add(new SelectListItem() { Text = textDefault, Value = valueDefault }); Type enumType = typeof(T); if (!enumType.IsEnum) { return list; } foreach (var item in Enum.GetNames(enumType)) { var field = enumType.GetField(item); string description = item; object[] arr = field.GetCustomAttributes(typeof(DescriptionAttribute), true); //獲取屬性字段數組 if (arr != null && arr.Length > 0) { description = ((DescriptionAttribute)arr[0]).Description; //屬性描述 } list.Add(new SelectListItem() { Text = description, Value = ((int)Enum.Parse(enumType, item)).ToString() }); } return list; }