Blazor code-behind: document partial class approach, retire base-class-only guidance#52472
Open
Blazor code-behind: document partial class approach, retire base-class-only guidance#52472
Conversation
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update documentation for code-behind syntax
Blazor code-behind: document partial class approach, retire base-class-only guidance
Mar 19, 2026
BillWagner
approved these changes
Mar 19, 2026
Member
BillWagner
left a comment
There was a problem hiding this comment.
This LGTM, and is ready for final review.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Blazor Web Forms migration guidance to reflect the modern code-behind pattern for Razor components, documenting the preferred partial class approach and demoting the older base-class-only (@inherits) guidance.
Changes:
- Document the preferred code-behind approach using a
partialclass with the same name as the component (no@inherits, private members allowed). - Retain the base class +
@inheritsapproach as an alternative, and add a callout about IDE duplication in IntelliSense/component lists. - Update article metadata (
ms.date, and addai-usage).
docs/architecture/blazor-for-web-forms-developers/components.md
Outdated
Show resolved
Hide resolved
docs/architecture/blazor-for-web-forms-developers/components.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Code-behind section only described the old base class +
@inheritsmodel, which was superseded when Blazor added partial class support. Using the base class pattern causes IDEs to surface both the component and its base class as separate entries in IntelliSense/component lists.Changes
@inherits, noBasesuffix, members can beprivatePreferred partial class pattern
Counter.razor — no
@inheritsneeded:Counter.razor.cs —
partial, same name,privatemembers work:The Razor compiler already emits a partial class for the component, so both parts merge at compile time without any explicit inheritance wiring.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews