Infolink

 

Search This Blog

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Oct 21, 2012

Working with Enums and Templates In ASP.NET MVC

Imagine you have the following types defined.

public class Movie
{
    public int Id { get; set; }
    public string Title { get; set; }
    public MovieGenre Genre { get; set; }
}

public enum MovieGenre
{
    Action,
    Drama,
    Adventure,
    Fantasy,
    Boring
}

If you want to display MovieGenre, the DisplayFor helpers generally give you what you expect (i.e. @Html.DisplayFor(m=> m.Genre) displays "Adventure"), but EditorFor will only give you a text input because the framework treats an enum the same as a string.
Related Posts Plugin for WordPress, Blogger...