Serge Serge - 20 days ago 5
C# Question

How to make a default editor template for enums in MVC 4?

We know that if we define a template for a base type, that template could serve also for the derived types (if any other template was not used to override it).

As we can't inherit an

Enum
, nor
enum
s are considered inherited from the
Enum
, so neither the
Enum.cshtml
template in the
Views\Shared\EditorTemplates
will not be active for different custom enum properties of the objects, like this one:

public enum Role
{
Admin,
User,
Guest
}


I already saw some answers on this topic for ASP in general, but I am wondering if in MVC 4 there are some improvements on this subject?

PS. I mean without use any explicit template attribution (like
@Html.EditorFor(model => model.Role, "Enum")
or
[UIHint("Enum")]
)

PPS. I am novice in MVC, so I'll appreciate your simple answers.

Answer

K. Scott Allen has a nice article about this.

Comments