[MVC]enum type을 DropDownList 로
[MVC]enum type을 DropDownList 로
public class EnumHelper { public static IEnumerable<SelectListItem> ToSelectList(Enum enumValue) { List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem() { Selected = true, Text = "--전체--", Value = "" }); var slt = (from Enum e in Enum.GetValues(enumValue.GetType()) select new SelectListItem { Selected = false, Text = e.ToString(), Value = e.ToString() }).ToList(); items.AddRange(slt); return items.AsEnumerable(); } }
@functions{ enum testEnum { a , b , c , d } }
@Html.DropDownList("drpTest", EnumHelper.ToSelectList(testEnum.a))
댓글
댓글 쓰기