dotnet / dotnet/aspnetcore

Custom ModelBindingMessageProvider implementation

Open
#32,177 3 comments 1 reaction 0 assignees View on GitHub
area-mvc enhancement feature-model-binding
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

A new way to provide a custom implementation of [ModelBindingMessageProvider]
For example If I have a form that have two properties the first one is of type **Int32** and the second on is of type **DataTime**
The validation error message of these types like that { The value ' ' is invalid } and to custom this error message you have one way to do that:

` services.Configure(options =>
{
options.ModelBindingMessageProvider.SetValueMustNotBeNullAccessor(value => "My Custom error message here...");
});`

But this custom error message will applying for all properties of type (Int32/DateTime) and so on.
And the the related issue is how to localize the custom message

![Capture](https://user-images.githubusercontent.com/18530495/116091144-3abdc380-a6ad-11eb-8411-813b1c1c0680.PNG)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.