Why @ Html.EnumDropDownList to add an empty (0) selection when you have numeric values ​​to enumerate?

I have two enumerations:

public enum AnnouncementType
{
    All = 1,
    Corporate = 2,
    Franchisee = 3
}

public enum AnnouncementLevel
{
    Urgent,
    Normal
}

The first, when using @ Html.EnumDropDownListFor, will add an empty parameter to the top of the drop-down list. The second behaves as expected and does not add an empty parameter. This has something to do with setting enumeration values. Is there a way to make him behave the same way as not having assigned values?

+4
source share
1 answer

0- The default value for the listing. In the second example Urgent- 0. Therefore, it does not need to be added. In the first example, no 0, so it creates it for you.

+7

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


All Articles