【发布时间】:2013-05-09 23:44:42
【问题描述】:
我已将[Display] 属性用于我的一个枚举:
public enum eCommentType
{
[Display(ResourceType = typeof(FaultManagementStrings), Name = "NormalComment")]
NormalComment = 0,
[Display(ResourceType = typeof(FaultManagementStrings), Name = "OpenningComment")]
OpenningComment = 1,
[Display(ResourceType = typeof(FaultManagementStrings), Name = "StartProgressComment")]
StartProgressComment = 2,
[Display(ResourceType = typeof(FaultManagementStrings), Name = "ClouserComment")]
ClouserComment = 3,
[Display(ResourceType = typeof(FaultManagementStrings), Name = "ReopennignComment")]
ReopennignComment = 4
}
是否可以创建一个扩展方法来重用现有的 MVC 功能,即从指定资源中获取 Display 属性值?
我想要那样的东西......
@Html.GetEnumDisplayAttributeValue(c=> comment.CommentType)
我知道我可以写一些东西来实现所需的反射并找到资源类型的值和调用资源管理器等等......但我认为也许可以使用现有的内置功能mvc.. 毕竟当你调用 LabelFor 助手时它已经完成了。
是可能的还是我应该重新发明轮子?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 reflection data-annotations html-helper