Currently I have a dropdown list based on an enum in a viewmodel. The enum in the viewmodel looks like this:
public enum Frequency
{
[Display(Name = "Daily")]
Daily,
[Display(Name = "Weekly")]
Weekly,
[Display(Name = "Monthly")]
Monthly
}
In my razor view, I create the dropdown like this:
@Html.EnumDropDownListFor(model => model.Frequency, "--- Select frequency for assignment ---", new { @class = "form-control", id = "frequency" })
And the model gets referenced in the razor view like this:
@model MyApplication.ViewModel.MyViewModel
This works great. However, I want to make a dropdown select list for this instead. I have seen lots of posts that do this with a select list you create in either the controller or the view itself, but I would like to use the enum that comes from the viewmodel. Is this possible? Is it possible to do this without editing the controller?
Any help/guidance is greatly appreciated. Thanks.
Update
I was able to get this working based on How do you create a dropdownlist from an enum in ASP.NET MVC? (Suggested in a response). I changed the view like this:
Html.DropDownList("Frequency", EnumHelper.GetSelectList(typeof(MyApplication.ViewModel.Frequency)), "--Select frequency--", new { @class = "form-control", id = "frequency" })
Thanks!