@ Html.EnumDropDownListFor on Core Asp.net

I am porting an MVC5 application to Asp.net 5 MVC6, vnext. I can not find

@Html.EnumDropDownListFor() 

Was it obsolete and is there a replacement? Where can I find documentation where all these minor changes can be found?

thanks

+6
source share
4 answers

just use asp-items="Html.GetEnumSelectList(typeof (State))" tag helper

 <select asp-for="State" asp-items="Html.GetEnumSelectList(typeof (State))"></select> 
+2
source

For those who are still looking for an answer, in ASP.NET 5 the functionality of EnumDropDownListFor () is obtained using DropDownListFor () in combination with the GetEnumSelectList () method. For instance:

 @model Enum @Html.DropDownListFor(m => m, Html.GetEnumSelectList(Model.GetType())) 

Note that you can decorate each enumeration value with custom display names, for example. include spaces. For instance:

 public enum CementTypes { [Display(Name = "Class S")]Class_S, [Display(Name = "Class N")]Class_N, [Display(Name = "Class R")]Class_R } 
+20
source

This is a pending feature. Tracking Issue: https://github.com/aspnet/Mvc/issues/438

+2
source

Or

 @model Enum @Html.DropDownListFor(m => m, Html.GetEnumSelectList(typeof(Enum))) 
0
source

Source: https://habr.com/ru/post/1207085/


All Articles