Skip to content

Restructure and trim the Blazor validation articles - #37488

Draft
oroztocil wants to merge 3 commits into
mainfrom
oroztocil/validation-docs-rework
Draft

Restructure and trim the Blazor validation articles#37488
oroztocil wants to merge 3 commits into
mainfrom
oroztocil/validation-docs-rework

Conversation

@oroztocil

@oroztocil oroztocil commented Aug 17, 2026

Copy link
Copy Markdown
Member

Reworks the Blazor forms validation documentation and adds coverage for the validation features introduced in .NET 11.

A companion pull request in the Blazor samples repository adds the sample projects that the new code references point to. This pull request should not be merged before that one, or the new :::code references won't resolve.

Why

The Blazor forms validation article had grown into a single 1,534-line page covering everything from "make this field required" to a multi-project remote validation tutorial. Its ordering worked against readers:

  • It opened with one of its most advanced scenarios. The first section taught hand-rolled validation: construct an EditContext, construct a ValidationMessageStore, subscribe to OnValidationRequested, write a handler. A reader whose actual question was "how do I validate this form" had to scroll past all of that to reach <DataAnnotationsValidator />.
  • The most fundamental behavior was documented last. The section explaining the DataAnnotationsValidator component's validation order and short-circuiting was the final section on the page, roughly 1,500 lines below the component it describes.
  • One section was a third of the article. The remote validation walkthrough was 34% of the rendered page, carried 27 inline code blocks, and had no subsections.
  • Custom validation was spread across five sections, interleaving two different mental models: declaring a rule on the model, and imperatively pushing messages into a store.
  • The choice of validation engine was buried and mis-framed. Calling AddValidation changes which fields are validated, whether messages are localized, and which client-side rules are emitted. It appeared only in a section near the end, presented as a nested-objects feature.
  • Shared concerns lived in the wrong place. Nested objects, custom rules, and localization are behaviors of Microsoft.Extensions.Validation and apply equally to Minimal APIs, but they were documented only in the Blazor article. The shared validation article had none of them.
  • Three .NET 11 features were undocumented or documented against APIs that no longer exist, including code samples that don't compile.

What changed

Blazor validation is now three articles

Article Covers
Blazor forms validation The default path: EditForm, DataAnnotationsValidator, displaying errors, and a table routing to everything else
Client-side validation in static SSR The .NET 11 feature, including its extensibility points
Advanced form validation EditContext, validator components, asynchronous validation, and the remote validation walkthrough

The entry-point article now opens with a working form as its first code sample, and the routing table appears near the top so readers self-select early.

Shared behavior moved to the shared article

Guidance that belongs to Microsoft.Extensions.Validation rather than to Blazor now lives in the validation article that both Blazor and Minimal API readers share, which also gives Minimal API readers examples they didn't have:

  • Writing custom validation rules with ValidationAttribute and IValidatableObject.
  • Validating nested objects and collections.
  • Localizing validation messages.
  • What happens when AddValidation isn't called, which differs between the two frameworks and previously wasn't stated anywhere.

The Blazor articles name each of these in Blazor terms and link down, so a reader who starts in the Blazor node still finds them.

New coverage for .NET 11

  • Client-side validation for static SSR forms: activation, supported attributes, which fields receive rules and why, timing, CSS classes, enhanced navigation, the streaming limitation, both opt-outs, and custom client-side rules.
  • Asynchronous validation through the EditContext API, and displaying pending and faulted state.
  • Validation message localization, including the lookup key conventions.

Corrections

Several sections documented APIs that were removed or renamed. Their samples didn't compile. These are rewritten against the shipping API, and the stale localization guidance elsewhere in the docs, which pointed at a package that no longer exists, is replaced with a pointer to the current guidance.

Trimming

The remote validation walkthrough and the custom CSS class provider guidance now reference sample projects instead of carrying their code inline, and both gained subsections. The per-field asynchronous validation example shows only what differs from the form-level example. Multi-assembly registration is one pattern with short per-framework notes rather than two near-identical walkthroughs.

Result

Rendered length for .NET 11:

Before After
Blazor forms validation 1,534 438
Client-side validation in static SSR - 232
Advanced form validation - 714
Validation in ASP.NET Core 235 483

The total grows, because three features gained coverage they didn't have, while the article most readers land on is about a third of its previous length.

Two topics that weren't validation topics moved out: the InputText input-event guidance moved to the forms binding article, and the custom CSS class provider guidance moved to the advanced article.

Verification

Checked across every supported version, from 3.1 through 11.0:

  • No in-page anchor is broken in any version, including links from other articles into the sections that moved.
  • Moniker blocks are balanced and code fences are matched in every changed file.
  • Every active sample reference resolves to a file in the samples repository.
  • Older versions still render coherent guidance. Version-specific sections such as [CompareProperty], the data annotations validation package, and the pre-.NET 10 nested objects approach continue to appear for the versions that need them.

The sample code was built and exercised at runtime, which surfaced four defects now fixed in the companion pull request: an unused using that broke a WebAssembly build, a missing package reference, two unused exception variables, and a missing _Imports.razor.

Notes

  • One :::code reference in the pre-.NET 8 content remains commented out. Those samples use a different file naming scheme, and mapping them needs a separate change.
  • The remote validation walkthrough keeps its current position in the advanced article. Its size problem was code volume rather than placement, so moving the code to samples addressed it without another article.

Internal previews

Toggle expand/collapse
File Preview link
aspnetcore/blazor/components/component-disposal.md aspnetcore/blazor/components/component-disposal
aspnetcore/blazor/forms/binding.md aspnetcore/blazor/forms/binding
aspnetcore/blazor/forms/index.md aspnetcore/blazor/forms/index
aspnetcore/blazor/forms/validation-advanced.md aspnetcore/blazor/forms/validation-advanced
aspnetcore/blazor/forms/validation-client-side.md aspnetcore/blazor/forms/validation-client-side
aspnetcore/blazor/forms/validation.md aspnetcore/blazor/forms/validation
aspnetcore/blazor/globalization-localization.md aspnetcore/blazor/globalization-localization
aspnetcore/fundamentals/localization/make-content-localizable.md aspnetcore/fundamentals/localization/make-content-localizable
aspnetcore/fundamentals/minimal-apis.md aspnetcore/fundamentals/minimal-apis
aspnetcore/fundamentals/validation.md aspnetcore/fundamentals/validation
aspnetcore/includes/not-latest-version.md aspnetcore/includes/not-latest-version
aspnetcore/release-notes/aspnetcore-11/includes/blazor.md aspnetcore/release-notes/aspnetcore-11/includes/blazor
aspnetcore/release-notes/aspnetcore-11/includes/validation-attributes-no-longer-experimental-preview-7.md aspnetcore/release-notes/aspnetcore-11/includes/validation-attributes-no-longer-experimental-preview-7
aspnetcore/release-notes/aspnetcore-11/includes/validation-localization-preview-7.md aspnetcore/release-notes/aspnetcore-11/includes/validation-localization-preview-7
aspnetcore/release-notes/aspnetcore-5.0.md aspnetcore/release-notes/aspnetcore-5.0
aspnetcore/release-notes/aspnetcore-7.0.md aspnetcore/release-notes/aspnetcore-7.0
aspnetcore/toc.yml aspnetcore/toc

@guardrex guardrex self-assigned this Aug 17, 2026
@guardrex

This comment was marked as resolved.

@oroztocil

Copy link
Copy Markdown
Member Author

@guardrex Please note that this is just a rough draft and work in progress. So please don't spend time reviewing it before I undraft the PR. 🙂

I will be OOF until August 24 so I will get to finish only then, unfortunately.

oroztocil and others added 3 commits August 24, 2026 17:12
Follow-up to the validation docs restructure. Reduces article length,
orders sections from the simplest and most common cases to the most
advanced, and moves sample code out of the articles.

Blazor forms validation

* Merges the three sections that described the DataAnnotationsValidator
  component into one, with validation order and short-circuiting as a
  subsection instead of the last section in the article.
* Folds the IValidatableObject stub and "Determine if a form field is
  valid" into the sections they belong to.
* Moves the table that routes readers to nested objects, localization,
  client-side validation, and the advanced article near the top, so a
  reader looking for one of those finds it early.
* Documents the default validation CSS classes, which were previously
  described only for static SSR.
* Moves the FieldCssClassProvider guidance to the advanced article, since
  it customizes validation rather than explaining it.

Advanced form validation

* The remote validation walkthrough now references sample projects instead
  of carrying its code inline, and gains subsections for each step.
* The per-field asynchronous validation example shows only what differs
  from the form-level example rather than repeating it.
* The FieldCssClassProvider section arrives here, references its sample
  files, and gains subsections.

Client-side validation in static SSR

* The custom rule example references its sample files.

Validation in ASP.NET Core

* Condenses multi-assembly registration to one pattern with short notes for
  Minimal APIs and Blazor, instead of two near-identical walkthroughs.

Rendered length, .NET 11: 607 to 438, 904 to 714, 283 to 232, and 521 to
483 lines respectively. Verified across all supported versions that no
in-page anchor is broken, moniker blocks are balanced, and every active
sample reference resolves.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 608096b5-db3e-4006-adaa-b4da0309ff87
@oroztocil
oroztocil force-pushed the oroztocil/validation-docs-rework branch from 3771431 to 1d6acd7 Compare August 25, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants