我已经使用了[Display]
属性为我的枚举之一:获得[显示]在MVC
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
}
是否有可能建立一种推广方法,将重用得到的exsisting MVC finctionallity显示指定资源的属性值?
我就什么类似的东西...
@Html.GetEnumDisplayAttributeValue(c=> comment.CommentType)
我知道我可以WIRTE的东西,将实施必要的反思和寻找资源类型的值和呼叫资源管理等..但我认为也许可以使用现有的mvc内置功能..毕竟,当您拨打LabelFor
助手时,它已经完成了。
是可能或应该重新发明轮子?
你能更具体吗?确切负责从显示属性和资源中提取信息的方法是什么? – Mortalus
@Mortalus我刚更新了描述。你应该关注的是'GetName'和'GetDisplayAttribute'方法,它们被用来提取display属性。 –