To use enum type in dropdown list follow the following format.
@Html.DropDownListFor(model => model.EnumName, new SelectList(Enum.GetValues(typeof(Namespace.EnumName))))
//Enum
namespace MyNameSpace.Util
{
public enum Days
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
}//Model
public EnumTestModel
{
MyNameSpace.Util.Days SelectedDay {get;set;}
}
Razor syntax for displaying Days in DropDownList is
// View
@Html.DropDownListFor(model => model.SelectedDay , new SelectList(Enum.GetValues(typeof(MyNameSpace.Util.Days))))
Comments
Post a Comment