4
Vote

Support enum properties

description

Enum properties should be shown as text on index, details, and delete screens, and should be shown as drop-down lists on create and edit screens.

Suggestions for text to display (thanks to Diego Viera):

Regarding how to Html.EditorFor() could pick the right descriptions for enums, here are some ideas that came to my mind.
  1. Default option: Tokenize PascalCase name

    public enum Color
    {
    Blue, // -> Blue
    LightBlue,  // -> Light blue
    ...
    }
  2. DisplayAttribute, non-localized:

    public enum Color
    {
    [Display(Name = "Blue", Description = "Blue color")]
    Blue,
    [Display(Name = "Light blue", Description = "Light blue  color")]
    LightBlue,
    ...
    }
  3. DisplayAttribute, localized

    public enum Color
    {
    [Display(ResourceType = typeof(DisplayResources), Name = "Blue", Description = "BlueDescription")]
    Blue,
    [Display(ResourceType = typeof(DisplayResources), Name = "LightBlue", Description = " LightBlueDescription")]
    LightBlue,
    ...
    }
  4. DiplayAttribute + convention: #3 is actually a lot of repetition. If we could change DisplayAttribute's usage to support using it on enums we could pick resource names by convention. Then the following would be equivalent to the example above:

    [Display(ResourceType = typeof(DisplayResources))]
    public enum Color
    {
    Blue,
    LightBlue,
    ...
    }

comments

KathleenDollard wrote Mar 19, 2011 at 3:08 PM

I think this is a much broader problem then MVC Scaffolding, but perhaps we could get a push for this at the DataAnnotations level.

In particular, the ability to put the resource indentifier on either the member or the type would be huge. This is one of the reasons I use customer resource managers.

So, a few additions:
  • Also allow a class based resource definition when determining convention based labels
  • Support alternate resource managers when doing that (assumed, but thought it worth stating)
  • Fallback #3, #2, #4, #1
This actually may wind up being difficult because of an issue with the framework. AFAIK, you still can't get the name of the property (PropertyInfo) or type (Type) an attribute is placed on from within code of the attribute. Fixing that would be fantastic.