【发布时间】:2018-05-31 09:21:40
【问题描述】:
我在 ASP.NET Core MVC 网站上工作,本地化在 Controller 和 View 中运行良好,但 DataAnnotation 的本地化出现错误:
如果是英语,我的默认语言和我的资源文件名如下:“Index.fr.resx”。
如果需要法语翻译,则使用翻译,否则返回字符串键(键为英文),
但是对于DataAnnotation,翻译效果很好,但是当需要英语时,网站会显示错误:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Intranet.Resources.ViewModels.News.Add.resources" was correctly embedded or linked into assembly
但是因为翻译工作找到了文件,并且对于Controller或View的本地化如果需要英文,则返回关键字符串并且工作正常,有什么想法吗?
Add.fr.resx:
Title => Titre
Add.cs
[Display(Name = nameof(Resources.ViewModels.News.Add.Title), ResourceType = typeof(Resources.ViewModels.News.Add))]
public String Title { get; set; }
Startup.cs
services.AddMvc(
config =>
{
config.Filters.Add<ActionFilter>();
})
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
【问题讨论】:
标签: c# asp.net-core localization asp.net-core-mvc data-annotations