すみません。トライ&エラーしていく中で自己解決してしまいましたので回答として掲載しておきます。
もっと上手いやり方があればご教授頂けると幸いです。m(__)m
IModelBindingMessageProviderをDependencyInjectionする方法とか...かな?
Startup.cs(抜粋)
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc(setup =>
{
var modelBindingMessageProvider = new ModelBindingMessageProviderLocalization();
setup.ModelBindingMessageProvider.ValueMustBeANumberAccessor = modelBindingMessageProvider.ValueMustBeANumberAccessor;
});
}
ModelBindingMessageProviderLocalization.cs(抜粋)
public class ModelBindingMessageProviderLocalization
{
private Func<string, string> _valueMustBeANumberAccessor;
public ModelBindingMessageProviderLocalization()
{
ValueMustBeANumberAccessor = Resources.FormatHtmlGeneration_ValueMustBeNumber;
}
public Func<string, string> ValueMustBeANumberAccessor
{
get
{
return _valueMustBeANumberAccessor;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_valueMustBeANumberAccessor = value;
}
}
}
Resources.resx(抜粋)
<data name="HtmlGeneration_ValueMustBeNumber" xml:space="preserve">
<value>{0} は数値を入力してください。</value>
</data>
Resources.Designer.cs(抜粋)
/// <summary>
/// The field {0} must be a number.
/// </summary>
internal static string HtmlGeneration_ValueMustBeNumber
{
get => ResourceManager.GetString("HtmlGeneration_ValueMustBeNumber");
}
/// <summary>
/// The field {0} must be a number.
/// </summary>
internal static string FormatHtmlGeneration_ValueMustBeNumber(object p0)
=> string.Format(CultureInfo.CurrentCulture, ResourceManager.GetString("HtmlGeneration_ValueMustBeNumber"), p0);
■実行結果
※今回は「"The field 値 must be a number."」というメッセージを書き換えるのが目的でしたが、ModelBindingMessageProviderは以下のメッセージを管理していますので、それらのメッセージを書き換える場合は同様にコードを記述すれば良いかと思われます。
上段:プロパティ名とリソース名
下段:メッセージ
MissingBindRequiredValueAccessor = Resources.FormatModelBinding_MissingBindRequiredMember;
A value for the '{0}' property was not provided.
MissingKeyOrValueAccessor = Resources.FormatKeyValuePair_BothKeyAndValueMustBePresent;
A value is required.
MissingRequestBodyRequiredValueAccessor = Resources.FormatModelBinding_MissingRequestBodyRequiredMember;
A non-empty request body is required.
ValueMustNotBeNullAccessor = Resources.FormatModelBinding_NullValueNotValid;
The value '{0}' is invalid.
AttemptedValueIsInvalidAccessor = Resources.FormatModelState_AttemptedValueIsInvalid;
The value '{0}' is not valid for {1}.
UnknownValueIsInvalidAccessor = Resources.FormatModelState_UnknownValueIsInvalid;
The supplied value is invalid for {0}.
ValueIsInvalidAccessor = Resources.FormatHtmlGeneration_ValueIsInvalid;
The value '{0}' is invalid.
ValueMustBeANumberAccessor = Resources.FormatHtmlGeneration_ValueMustBeNumber;
The field {0} must be a number.
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/ModelBindingMessageProvider.cs
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Resources.resx
から引用