Skip to content

Use model display names in Blazor input parsing errors - #68667

Merged
ilonatommy merged 3 commits into
dotnet:mainfrom
ilonatommy:fix-68609
Aug 21, 2026
Merged

Use model display names in Blazor input parsing errors#68667
ilonatommy merged 3 commits into
dotnet:mainfrom
ilonatommy:fix-68609

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Aug 20, 2026

Copy link
Copy Markdown
Member

Fixes #68609

see: #68609 (comment)

Blazor input components currently use the CLR property name in parsing validation messages unless their DisplayName parameter is explicitly set. This produces inconsistent output when the same field is rendered using DisplayName or Label.

For example, a property annotated with [DisplayName("Unit Price")] renders a Unit Price label but an empty InputNumber reports:

The UnitPrice field must be a number.

This change makes input parsing errors use the display name resolved from the bound member's [Display] or [DisplayName] attribute.

The resolution order is:

  1. The explicit InputBase.DisplayName parameter
  2. The bound member's [Display] or [DisplayName] metadata
  3. The existing CLR field-name fallback

The existing ExpressionMemberAccessor is reused, so display-name precedence, localization, and caching remain consistent with the DisplayName and Label components.

The shared behavior applies to parsing failures from InputNumber, InputDate, InputSelect, and InputRadioGroup.

@ilonatommy ilonatommy added this to the 11.0-rc1 milestone Aug 20, 2026
@ilonatommy
ilonatommy requested a review from maraf August 20, 2026 15:36
@ilonatommy ilonatommy self-assigned this Aug 20, 2026
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-validation Issues related to model validation in minimal and controller-based APIs labels Aug 20, 2026
@ilonatommy
ilonatommy marked this pull request as ready for review August 21, 2026 07:39
@ilonatommy
ilonatommy requested a review from a team as a code owner August 21, 2026 07:39
@ilonatommy
ilonatommy requested review from akoeplinger and a lite review from Copilot August 21, 2026 07:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Blazor input parsing errors to use explicit display names or bound model metadata, with CLR field-name fallback.

Changes:

  • Centralizes display-name resolution in InputBase.
  • Applies resolved names to numeric, date, select, and radio parsing errors.
  • Adds unit, sample, and E2E coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Summary
src/Components/Web/test/Forms/InputNumberTest.cs Tests display metadata for numeric parsing errors.
src/Components/Web/src/Forms/InputNumber.cs Uses resolved display names in numeric errors.
src/Components/Web/src/Forms/InputExtensions.cs Updates select and radio parsing errors. Nit (3 votes): add model-attribute coverage for both consumers.
src/Components/Web/src/Forms/InputDate.cs Uses resolved display names in date errors. Nit (3 votes): add model-metadata coverage for this path.
src/Components/Web/src/Forms/InputBase.cs Resolves explicit, metadata-based, and fallback display names.
src/Components/test/testassets/BasicTestApp/FormsTest/DisplayNameComponent.razor Adds the display-name validation scenario.
src/Components/test/E2ETest/Tests/FormsTest.cs Adds browser coverage for the validation message.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Components/Web/src/Forms/InputDate.cs
Comment thread src/Components/Web/src/Forms/InputExtensions.cs

@maraf maraf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me & my copilot 👍

@ilonatommy
ilonatommy requested a review from maraf August 21, 2026 08:38
Comment thread src/Components/Web/src/Forms/InputBase.cs
@ilonatommy
ilonatommy requested a review from akoeplinger August 21, 2026 11:26
@ilonatommy
ilonatommy merged commit a114d2c into dotnet:main Aug 21, 2026
29 checks passed
@ilonatommy

Copy link
Copy Markdown
Member Author

/backport to release/11.0-rc1

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-rc1 (link to workflow run)

@ilonatommy ilonatommy modified the milestones: 11.0-rc1, 12.0-preview1 Aug 21, 2026
wtgodbe pushed a commit that referenced this pull request Aug 21, 2026
* Use display attributes in input parsing errors

* Address test coverage feedback from review.

* Apply dedup cleanup from feedback.

Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
wtgodbe added a commit that referenced this pull request Aug 22, 2026
* [SignalR] Reject duplicate SignalR upload stream IDs (#68525) (#68638)

* Reject duplicate SignalR upload stream IDs



* Simplify upload stream ownership cleanup



* Avoid upload stream ownership allocations



* Simplify upload stream registration ownership



* Defer upload stream reader creation





* Dispose cancellation source after binding failure





* Reuse upload stream test helper





---------

Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 82e97f5a-a052-4dbe-9cf1-b62f45cf7ee2

* Honor all sign-in confirmation requirements after registration (#68631) (#68655)

Co-authored-by: Brennan <brecon@microsoft.com>

* Preserve BadHttpRequestException status codes (#68632) (#68649)

* Preserve BadHttpRequestException status codes



* Preserve exception handler 404 safeguard



---------

Co-authored-by: Stephen Halter <halter73@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* SignInManager: return SignInResult.Failed for expired passkey session challenge (#67539) (#68654)

Co-authored-by: Grant Totinov <granttotinov604@gmail.com>

* Don't apply the CSRF verdict to remote authentication callbacks (#68669)

* Don't apply the CSRF verdict to remote authentication callbacks

A remote provider's callback (OIDC response_mode=form_post, WS-Federation)
is a cross-site form POST by protocol design, so the auto-injected CSRF
protection records an invalid IAntiforgeryValidationFeature verdict for it.
The handler then throws while reading its own callback body, before any of
its events can run, so apps have no way to opt out.

Suppress the verdict while a remote handler owns the request, and restore it
if the handler declines so the rest of the pipeline still sees it.

Fixes #68666

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cb987098-3301-465b-9a3d-2e63aabf43bd

* test both antiforgery & csrf

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cb987098-3301-465b-9a3d-2e63aabf43bd

* Use model display names in Blazor input parsing errors (#68667) (#68688)

* Use display attributes in input parsing errors

* Address test coverage feedback from review.

* Apply dedup cleanup from feedback.

Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>

* [release/11.0-rc1] Extract IsAuthenticated helper method (#68658)

* Extract IsAuthenticated helper method

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>

* Reorder using

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>

* Use SecurityHelper for authentication revalidation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>

---------

Co-authored-by: Youssef1313 <youssefvictor00@gmail.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Milos Kotlar <kotlarmilos@gmail.com>

* Fix  InitialItemIndex viewport underfill for small items in big container or on window resize (#67936) (#68689)

Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>

* fix nullable<union> for openapi gen (#68665)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Brennan <brecon@microsoft.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>
Co-authored-by: Grant Totinov <granttotinov604@gmail.com>
Co-authored-by: Korolev Dmitry <dmkorolev@microsoft.com>
Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Youssef1313 <youssefvictor00@gmail.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Milos Kotlar <kotlarmilos@gmail.com>
Co-authored-by: William Godbe <wigodbe@microsoft.com>
Copilot-Session: 82e97f5a-a052-4dbe-9cf1-b62f45cf7ee2
Copilot-Session: cb987098-3301-465b-9a3d-2e63aabf43bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components feature-validation Issues related to model validation in minimal and controller-based APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation Message Displays Property Name Instead of Display Attribute Value

4 participants