Home >Backend Development >C++ >How Can I Localize the Display Name of a Model Property in ASP.NET MVC?
Localization of DisplayName Attribute
The DisplayName attribute is used to specify the display name for a model property. However, if you need to localize the display name based on the current culture, you'll encounter a limitation with using the traditional DisplayName attribute.
In this situation, you can use the new Display attribute introduced in MVC 3 and .NET 4. The Display attribute provides extended functionality, including localization support.
Solution:
To localize the display name of a model property:
public class MyModel { [Required] [Display(Name = "labelForName", ResourceType = typeof(Resources.Resources))] public string name{ get; set; } }
The Display attribute takes a Name parameter to specify the resource key and a ResourceType parameter to specify the resource file containing the localized strings.
Note:
The above is the detailed content of How Can I Localize the Display Name of a Model Property in ASP.NET MVC?. For more information, please follow other related articles on the PHP Chinese website!