Search code examples
asp.net-mvc-3drop-down-menueditorformodel

MVC3 EditorForModel Dropdown


I am using @Html.EditorForModel() in several places, and I was just wondering if there is a simple attribute to specify that something should be a dropdownlist in the view model? An approximate example of what I am looking for would be...

public class MyViewModel
{
    [DropDown("red", "blue", "green")]
    public string Lasers { get; set; }
}

I know there have been similar questions asked, and I know that I can make a custom template that would implement something like this... I was wondering if this seemingly simple functionality already existed, or if there was some sort of NuGet package that added this functionality. This just seems too basic to not exist somewhere, and I might have to make a NuGet package myself if there isn't something already.

Thanks in advance everybody!


Solution

  • Follow this link

    http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx

    search for "CountryDropDown" on this page to get to the answer