I am migrating an application from previous ASP.NET version to ASP.NET 5(vNext, MVC 6). Previously I localized forms with DisplayAttribute
attached to ViewModel's properties:
[Required(ErrorMessageResourceName = "FieldIsRequired", ErrorMessageResourceType = typeof(Resources.Validation))]
[Display(Name = "UserName", ResourceType = typeof(Resources.Common))]
public string UserName { get; set; }
I added DataAnnotations service:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddViewLocalization(options => options.ResourcesPath = "Resources/Views")
.AddDataAnnotationsLocalization();
}
When I submit an invalid form, an error message gets localized (as specified in the [Required]
attribute).
But trying to display the form, I got an exception (No public property "UserName" in the resource class), until I commented out [Display]
attribute.
Seems like input labels can't be localized with [DisplayAttribute]
anymore?
Thank you!