如何在MVC 4枚举默认编辑模板? [英] How to make a default editor template for enums in MVC 4?

查看:152
本文介绍了如何在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).

由于不能继承一个枚举,也不枚举 s被认为从<$ C $继承C>枚举,所以在 Enum.cshtml 模板>正文\\共享\\ EditorTemplates 不会为对象的不同的自定义枚举的属性活跃,像这样的:

As we can't inherit an Enum, nor enums 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
}

我已经看到了关于这个主题的ASP一般一些答案,但我在想,如果 MVC 4 有关于这个问题的一些改进?

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。我的意思的没有的使用任何显式模板属性(如 @ Html.EditorFor(型号=&GT; model.Role,枚举) [UIHint(枚举)]

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

PPS。我在MVC新手,所以我将AP preciate您简单的答案。

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

推荐答案

K。斯科特·艾伦在<关于这个好文章href=\"http://odeto$c$c.com/blogs/scott/archive/2012/09/04/working-with-enums-and-templates-in-asp-net-mvc.aspx\" rel=\"nofollow\">http://odeto$c$c.com/blogs/scott/archive/2012/09/04/working-with-enums-and-templates-in-asp-net-mvc.aspx

这篇关于如何在MVC 4枚举默认编辑模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆