I am trying to convert my Items from Enum to a dropdownlist .Please help
public enum Colors{ red,blue,green,yellow,orange,white,black,Teal,Custom } @Html.DropDownList("SelectedColourId", Model.ColourList, "(Select one Color)") My ViewModel is below
myPageViewModel:BasicViewModel { ..... public IEnumerable<SelectListItem> ColourList{ get; set; } ......... } I am tried something like
myViewModel.ColourList = Enum.GetNames(typeof(Colors)).ToArray() .Select(e => new SelectListItem() { Text = e.item, Value = e.itemindex }); But I don't know how to get itemText and its correesponding Index .Its throwing errors