I've searched about a bit and can't find an answer specifically to my question.
I have an Enum:
public enum CodeType
{
NotSpecified,
Absent,
NoAbsence,
Other,
Missing
}
The above Enum is stored in a struct. I am trying to edit the stored Enum in a view using a DropDownList, which works great, except my only issue is I am trying to set the default value of that DropDownList to the model's stored Enum. See below:
@Html.DropDownList("c", EnumHelper.GetSelectList(typeof(CodeType)),Enum.GetValues(typeof(CodeType)))
As the second argument, I have tried using:
@Html.DropDownList("c", EnumHelper.GetSelectList(typeof(CodeType)),Enum.GetValues(typeof(Model.CodeType.ToString())))
However, that does display the stored Enum value as a string in the DropDownList, but if the user hits the submit button, I get an error for a null variable unless the user explicitly clicks on the DropDownList and selects an item.
Any ideas how I can properly use Model.CodeType as the default value in the DropDownList?