ASP.NET CORE 2.0中的ASP.NET Core模型绑定错误消息本地化 [英] ASP.NET Core Model Binding Error Messages Localization in ASP.NET CORE 2.0
问题描述
在ASP.NET CORE 1.1中,可以使用资源文件来本地化模型绑定错误消息,并可以在
In ASP.NET CORE 1.1 it was possible to localize model binding error messages using a resource file and configure its options to set message accessors for ModelBindingMessageProvider in the Startup.cs like
services.AddMvc(options =>
{
var F = services.BuildServiceProvider().GetService<IStringLocalizerFactory>();
var L = F.Create("ModelBindingMessages", null);
options.ModelBindingMessageProvider.ValueIsInvalidAccessor =
(x) => L["The value '{0}' is invalid."];
如下所示: ASP.NET核心模型绑定错误消息本地化,然后在此处: https: //blogs.msdn.microsoft.com/mvpawardprogram/2017/05/09/aspnetcore-mvc-error-message/
as shown here: ASP.NET Core Model Binding Error Messages Localization and here: https://blogs.msdn.microsoft.com/mvpawardprogram/2017/05/09/aspnetcore-mvc-error-message/
在ASP.NET CORE 2.0中,我收到有关ModelBindingMessageProvider的所有属性的错误消息
In ASP.NET CORE 2.0 I receive an error message on all of the ModelBindingMessageProvider's properties
options.ModelBindingMessageProvider.ValueIsInvalidAccessor
是只读的
如何在ASP.NET CORE 2.0中本地化这些消息
How can these messages be localized in ASP.NET CORE 2.0
推荐答案
我也遇到了这个问题.这些设置器已替换为诸如SetValueIsInvalidAccessor
之类的方法,更改描述如下: https://github.com/aspnet/Announcements/issues/240
I also ran into this. These setters were replaced with methods such as SetValueIsInvalidAccessor
, the change is described here: https://github.com/aspnet/Announcements/issues/240
这篇关于ASP.NET CORE 2.0中的ASP.NET Core模型绑定错误消息本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!