Home How do you create a dropdownlist from an enum in ASP.NET MVC?
Reply: 0

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

user504
1#
user504 Published in June 20, 2018, 10:53 pm

I'm trying to use the Html.DropDownList extension method but can't figure out how to use it with an enumeration.

Let's say I have an enumeration like this:

public enum ItemTypes
{
    Movie = 1,
    Game = 2,
    Book = 3
}

How do I go about creating a dropdown with these values using the Html.DropDownList extension method?

Or is my best bet to simply create a for loop and create the Html elements manually?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.47381 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO