I am trying to use localization with the data model annotations.
Update: added example code and changed the example to reflect the code
I have prepared a small non-working example which can be cloned from here https://bitbucket.org/feradz/dataannotationlocalization.git
To load the page browse to http://localhost:6092/PersonalInfo/Edit
I have the following class:
public class PersonalInfo
{
[Display(Name = "NameDisplay", ResourceType = typeof(PersonalInfo))]
[Required(ErrorMessageResourceName = "NameRequired", ErrorMessageResourceType = typeof(PersonalInfo))]
public string Name { get; set; }
}
I have created DataAnnotationLocalization.ViewModels.Member.PersonalInfo.resx and DataAnnotationLocalization.ViewModels.Member.PersonalInfo.es.resx resource files in directory Resources.
In DataAnnotationLocalization.ViewModels.Member.PersonalInfo.resx and DataAnnotationLocalization.ViewModels.Member.PersonalInfo.es.resx I have defined NameDisplay=Name EN and NameDisplay=Name ES respectively.
When I try to load the page I get the following error.
An unhandled exception occurred while processing the request.
InvalidOperationException: Cannot retrieve property 'Name' because localization failed. Type 'DataAnnotationLocalization.ViewModels.Member.PersonalInfo' is not public or does not contain a public static string property with the name 'resourceNameKey'.
System.ComponentModel.DataAnnotations.LocalizableString.<>c__DisplayClass12_0.<GetLocalizableValue>b__1()
Is there any out-of-the-box support for this in ASP.NET 5 MVC6?