Models { public class FoodModel { public FoodEnum Food { get; set; } } } Finally, we add a EnumDropDownListFor to the View, so that a simple drop-down menu can be completed: Talking-about-the-drop-down-list-menu-in-.NET-Framework-and-.NET-Core-01 : We discovered a problem here, that is, although the default option has been added, the initial value is still the first item in the enum.
This is because in the Model, the type FoodEnum we declare must not be null. value, and when EnumDropDownListFor is presented, if the value value is null, or the option does not contain a value, the initial default will be set to the option with a value of 0, so we only business data need to change the type FoodEnum in the Model to FoodEnum ? , so that even if the value of the default option is null during presentation, the item with value 0 will not be forced to be selected.
Then we add an additional required attribute to restrict the front-end from being unselected and avoid submission. When sending null value: namespace WebApplication.Models { public class FoodModel { [Required] public FoodEnum? Food { get; set; } } } The results presented are shown below: Talking-about-the-drop-down-list-menu-in-.NET-Framework-and-.NET-Core The above is the implementation of EnumDropDownListFor in .NET Framework. 2. List drop-down menu in NET Core In .