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

Posted by Kevin Pang on Stack Overflow See other posts from Stack Overflow or by Kevin Pang
Published on 2008-12-23T09:25:43Z Indexed on 2010/03/12 2:07 UTC
Read the original article Hit count: 334

Filed under:

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc