【发布时间】:2011-02-11 00:36:23
【问题描述】:
当我在 ASP.NET MVC 3 模型中使用 DisplayAttribute 时,编写它们很快就会变得很痛苦,因为我们必须对字符串进行硬编码或从包含 const strings 的某个静态类中引用字符串(这就是我现在所拥有的) , 见下文)。但即使这样对我来说也太过分了。
我想提出一个类似于 [SimpleDisplay] 的属性,它会通过查看
来隐式构造资源字符串- 类名,
- 属性附加到的属性名称。
这可能吗?
类似的东西
public class Product {
[SimpleDisplay] // it will take Product and Name and do something like this Product_Name
public string Name { get; set; }
}
如果可能的话,这就是我想要摆脱的:
[Display(ResourceType = typeof(Resources.Localize), Name = ResourceStrings.product_prettyid)]
public virtual int PrettyId
{
get;
set;
}
[Display(ResourceType = typeof(Resources.Localize), Name = ResourceStrings.product_name)]
public virtual string Title
{
get;
set;
}
现在我知道不能继承 DisplayAttribute 因为它是密封的。我还有什么其他选择?它甚至有意义吗?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 data-annotations