---
title: "Dropdownlist from an enum in ASP.NET MVC"  
description: "Dropdownlist from an enum in ASP.NET MVC"  
author: "Jayden Bell"  
published: 2014-11-18  
updated: 2014-11-18  
canonical: https://www.mindstick.com/forum/12631/dropdownlist-from-an-enum-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["mvc", "dropdown"]  
reading_time: 1 minute  

---

# Dropdownlist from an enum in ASP.NET MVC

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to use the Html.DropDownList [extension method](https://www.mindstick.com/articles/22/extension-method) but can't [figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out how to use it with an [enumeration](https://www.mindstick.com/blog/88/enumeration-in-c-sharp).

**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](https://www.mindstick.com/articles/263/ajax-toolkit-dropdownextender-in-asp-dot-net) with these [values](https://www.mindstick.com/forum/327/sum-textbox-values) using the Html.DropDownList extension method? Or is my best bet to simply create a [for loop](https://www.mindstick.com/forum/12568/android-for-loop-not-working-in-main-thread) and create the [html elements](https://www.mindstick.com/forum/158688/how-can-you-dynamically-create-html-elements-using-jquery) manually?

## Replies

### Reply by Takeshi Okada

I rolled Rune's answer into an extension [method](https://www.mindstick.com/forum/166/webservice-method):

```
namespace MyApp.Common{    public static class MyExtensions{        public static SelectList ToSelectList<TEnum>(this TEnum enumObj)            where TEnum : struct, IComparable, IFormattable, IConvertible        {            var values = from TEnum e in Enum.GetValues(typeof(TEnum))                select new { Id = e, Name = e.ToString() };            return new SelectList(values, "Id", "Name", enumObj);        }    }}
```

This allows you to write:

ViewData["taskStatus"] = task.Status.ToSelectList();

by using MyApp.Common


---

Original Source: https://www.mindstick.com/forum/12631/dropdownlist-from-an-enum-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
