Enums are great to help you strongly reference values without using “magic” strings. Normally I use them in conditional if statements. However, recently I wanted to get all values into a List, where T is your Enum. Let’s explore how Enum.GetValues will help.
Tag: enum
-
Create MVC DropDownList from an Enum
Like many requested features, MVC 5 now has a built-in function to provide an Enum object and automatically build a dropdown list using the standard HtmlHelper. If you’re unfortunate and on an older version of MVC, here is an HtmlExtension that performs the same thing.