Using enum for dropdown list in ASP.NET MVC Core

后端 未结 8 1197
你的背包
你的背包 2021-01-31 06:51

I\'m trying to create a dropdown list with an enum property in ASP.NET MVC Core using the tag helper in a Razor view:

Here is the model:

public class Per         


        
相关标签:
8条回答
  • 2021-01-31 07:41

    you use Gender to asp-items="Html.GetEnumSelectList -GenderType- ()" instead of GenderType

    such as asp-items="Html.GetEnumSelectList -Gender- ()"

    0 讨论(0)
  • 2021-01-31 07:42

    I think you accidentally used GenderType instead of Gender. The correct syntax is

    <select asp-for="GenderType" asp-items="Html.GetEnumSelectList<Gender>()">
        <option selected="selected" value="">Please select</option>
    </select>
    
    0 讨论(0)
提交回复
热议问题