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."];
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/
In ASP.NET CORE 2.0 I receive an error message on all of the ModelBindingMessageProvider's properties
options.ModelBindingMessageProvider.ValueIsInvalidAccessor
is readonly
How can these messages be localized in ASP.NET CORE 2.0
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