0
当使用DataAnnotations.Display
属性与本地化字符串相结合,这是所使用的语法如下:如何避免ASP.NET MVC显示属性中的字符串型代码?
public class Customer
{
[Display(ResourceType = typeof(DisplayResources), Name = "LName")]
public string LastName { get; set; }
}
来源:MSDN。
显然,下面的语法是不可能的:
public class Customer
{
[Display(Name = DisplayResources.LName)]
public string LastName { get; set; }
}
,因为它会导致以下编译错误:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
还有什么我可以做,以避免他们的名字传递变量通过串?有没有办法避免字符串型代码?
我看到有人在行使其新获得的[编程术语词汇(HTTP://www.codinghorror。 COM /博客/ 2012/07 /新编程-jargon.html)。 – BoltClock 2012-07-21 09:00:05