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

This question already has an answer here:

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

  • In your view you can use SelectExtensions.EnumDropDownListFor:

    Eg:

    @Html.EnumDropDownListFor(model => model.Countries)
    

    given that the @model of the view has a property named Countries that is an enum type.

    If you want to show a default text in the drop down (like: "Select country"). Take a look at the following question and answer.

    Html.EnumDropdownListFor: Showing a default text

    链接地址: http://www.djcxy.com/p/48130.html

    上一篇: ASP.NET MVC Core / 6:多个提交按钮

    下一篇: 如何从ASP.NET MVC中的枚举创建下拉列表?