en-US:
zh-CN:
Why are [Display(Name = "LoginUserName")] and other data annotations not working?
This is my localization config
What could be the fix for me?
You can try the following two ways:
1. Use the old way of localizing data annotations:
[Display(Name = nameof(MyResources.LoginUserName),
ResourceType = typeof(MyResources))]
2. DataAnnotation localization can be configured in the startup file(Put in Program.cs in .NET 6):
services.AddMvc()
.AddViewLocalization(o=>o.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization(o=> {
var type = typeof(ViewResource);
var assemblyName = new AssemblyName(type.GetTypeInfo().Assembly.FullName);
var factory = services.BuildServiceProvider().GetService<IStringLocalizerFactory>();
var localizer = factory.Create("ViewResource", assemblyName.Name);
o.DataAnnotationLocalizerProvider = (t, f) => localizer;
});
Here is a work demo, you can refer to it.
Hope this can help you.