dotnet / dotnet/aspnetcore

Blazor Static SSR ParsableConverter mapping error message customization

Open
#56,484 4 comments 0 reactions 0 assignees View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

[https://github.com/dotnet/aspnetcore/blob/94259788d58e16ba753900b4bf855a6aee08dcb1/src/Components/Endpoints/src/FormMapping/Converters/ParsableConverter.cs#L22](url)
`var segment = reader.GetLastPrefixSegment();
reader.AddMappingError(FormattableStringFactory.Create(FormDataResources.ParsableMappingError, value, **segment**), value);
result = default!;
return false;`
It means what we don't have a simple ability to format this validation message better. The main problem as it doen't use a property display attribute caption, just a property name in a model class.

### Describe the solution you'd like

That's possible it can be a quite handy thing when we have an ability to customize the validation message in a some simple way.
MVC/Razor Pages projects provide AttemptedValueIsInvalidAccessor inside the ModelBindingMessageProvider.

Blazor static SSR doesn't have any options for customization in this case.
*ParsableConverter* is an *"internal"* class as well as other related classes.
So there is no a simple way to override them in a user code.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with src/Components/Endpoints/src/FormMapping/Converters/ParsableConverter.cs at the ParsableConverter mapping-error call, then compare the requested customization with MVC/Razor Pages' ModelBindingMessageProvider and AttemptedValueIsInvalidAccessor. Done means Blazor static SSR offers a simple way to customize this validation message, including a property display caption instead of only the model property name.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.