It s a modelbinding error not model validation error,you may try set here:
builder.Services.AddControllers(op => op.ModelBindingMessageProvider.SetNonPropertyAttemptedValueIsInvalidAccessor(input => input+" invalid")) ;
Result:
For more detailed error message, you need to custom model binder,for example:
public class MyBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
var modelName = bindingContext.ModelName;
// Try to fetch the value of the argument by name
var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
if (valueProviderResult == ValueProviderResult.None)
{
return Task.CompletedTask;
}
bindingContext.ModelState.SetModelValue(modelName, valueProviderResult);
var value = valueProviderResult.FirstValue;
if (!short.TryParse(value, out var id))
{
bindingContext.ModelState.TryAddModelError(
modelName, value+" is not valid for short.");
return Task.CompletedTask;
}
return Task.CompletedTask;
}
}
Apply the modelbinder :
[ModelBinder(BinderType = typeof(MyBinder))] short someValue
Result: