When using DataAnnotations.Display attribute combined with localized strings, the syntax which is used is the following:
public class Customer
{
[Display(ResourceType = typeof(DisplayResources), Name = "LName")]
public string LastName { get; set; }
}
Source: MSDN.
Apparently, the following syntax is impossible:
public class Customer
{
[Display(Name = DisplayResources.LName)]
public string LastName { get; set; }
}
since it results in the following compile error:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
What else I can do to avoid passing variables by their names through a string? Is there a way to avoid stringly-typed code?
there is an article form ex-Telerik member Kazi Manzur Rashid. Localization with ASP.NET MVC ModelMetadata. He is explaining there how to use nice framework MvcExtensions (help articles)
Here is an example: