How do you create a dropdownlist from an enum in ASP.NET MVC?

后端 未结 30 2429
不知归路
不知归路 2020-11-21 16:36

I\'m trying to use the Html.DropDownList extension method but can\'t figure out how to use it with an enumeration.

Let\'s say I have an enumeration like

30条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 16:52

    Now this feature is supported out-of-the-box in MVC 5.1 through @Html.EnumDropDownListFor()

    Check the following link:

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/releases/mvc51-release-notes#Enum

    It is really shame that it took Microsoft 5 years to implement such as feature which is so in demand according to the voting above!

提交回复
热议问题