【发布时间】:2011-09-08 20:38:05
【问题描述】:
在 MVC3 项目中,我使用带有显示属性的枚举:
public enum Foo {
[Display(Name = "Undefined")]
Undef = 0,
[Display(Name = "Fully colored")]
Full = 1
}
模型类有一个使用这个枚举的属性:
public Foo FooProp { get; set; }
视图使用模型类并通过显示属性
@Html.DisplayFor(m => m.FooProp)
现在,最后,我的问题:
如何让 .DisplayFor() 显示来自 Display-Attribute 的字符串,而不是仅显示枚举的值名称? (它应该显示“未定义”或“全彩色”,但显示“未定义”或“全色”)。
感谢您的提示!
【问题讨论】:
标签: asp.net-mvc-3 attributes enums