Skip to content

Fix Blazor CRUD Edit state persistence across prerender and interactive rendering - #3830

Merged
haileymck merged 10 commits into
dotnet:mainfrom
MohamedFasulAshab:fix/3445-blazor-edit-persistent-state
Sep 21, 2026
Merged

haileymck merged 10 commits into
dotnet:mainfrom
MohamedFasulAshab:fix/3445-blazor-edit-persistent-state

Conversation

@MohamedFasulAshab

Copy link
Copy Markdown
Contributor

Summary

Blazor CRUD scaffolding now preserves Edit page model state across prerender-to-interactive transitions, so loaded model data is retained when interactivity starts.

The change applies version-specific persistence strategies:

  • .NET 8/.NET 9: PersistentComponentState (TryTakeFromJson, PersistAsJson, RegisterOnPersisting)
  • .NET 10/.NET 11: declarative [PersistentState] via separate state property

This prevents Edit-page state loss/flicker during hydration and keeps form-bound model flow intact.

Changes

  • Updated Blazor CRUD Edit templates for:
    • net8.0
    • net9.0
    • net10.0
    • net11.0
  • Kept [SupplyParameterFromForm] model binding separate from persisted model state in .NET 10/11.
  • Added/updated persistence-focused test coverage for Edit template generation and integration checks.
  • Tightened integration assertions so expected scaffolded outputs are validated consistently.
  • Synced template source and preprocessed generated template classes.

Validation

  • Built dotnet-scaffold successfully.
  • Ran focused Blazor CRUD template tests for Edit persistence generation.
  • Ran focused Blazor CRUD integration tests for enabled framework suites.
  • Verified generated Edit.razor includes framework-appropriate persistence logic.
  • Verified generated projects still build after scaffolding.

Compatibility

  • No public API changes.
  • Blazor CRUD scope only (Edit page persistence behavior).
  • Existing non-Edit scaffolding behavior remains unchanged.
  • Version-specific implementation chosen to match framework capability differences.

Known Limitations

  • Full browser-driven hydration behavior automation is not included in this patch.
  • net11 integration execution remains subject to repository test policy/SDK availability.
  • Persistence payload currently serializes scaffolded model state as generated by templates.

Output Screenshots

Attach:
image
image
image

Fixes #3445.

MohamedFasulAshab and others added 10 commits September 7, 2026 15:08
…829.11 (dotnet#3812)

On relative base path root
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore , Microsoft.AspNetCore.Identity.EntityFrameworkCore , Microsoft.AspNetCore.Identity.UI , Microsoft.EntityFrameworkCore , Microsoft.EntityFrameworkCore.Design , Microsoft.EntityFrameworkCore.SqlServer , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Binder , Microsoft.Extensions.Configuration.CommandLine , Microsoft.Extensions.Configuration.EnvironmentVariables , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.Configuration.UserSecrets , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyModel , Microsoft.Extensions.FileProviders.Embedded , Microsoft.Extensions.FileProviders.Physical , Microsoft.Extensions.Identity.Stores , Microsoft.Extensions.Logging , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Options.ConfigurationExtensions , System.Text.Json From Version 11.0.0-rc.1.26411.119 -> To Version 11.0.0-rc.2.26429.111
Microsoft.DotNet.Arcade.Sdk From Version 11.0.0-beta.26411.119 -> To Version 11.0.0-beta.26429.111

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
@MohamedFasulAshab
MohamedFasulAshab marked this pull request as ready for review September 16, 2026 13:52
@haileymck

Copy link
Copy Markdown
Member

what dev loop are you running? are you installing the changes in your dotnet scaffold CLI and then running the scaffolding on the CLI and viewing the changes in VS? wanting to verify if you are scaffolding from CLI or VS because of the screenshots

@MohamedFasulAshab

MohamedFasulAshab commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for checking. During development, I launched the dotnet-scaffold project directly from the repository using the Visual Studio debug profile and passed the aspnet blazor-crud arguments against separate Blazor target projects.

I also completed the final validation through the locally built and installed dotnet scaffold (20.1.0-dev) and dotnet-aspnet-codegenerator (11.0.0-dev) CLI tools. Both tools generated the expected CRUD pages, and the resulting applications built and ran successfully.

Visual Studio was used afterward to inspect the generated Edit.razor files and verify state persistence across prerendering and interactive rendering. The implementation and automated template coverage include all supported target-framework versions.

I hope this clarifies the development and validation workflow. Please let me know if any additional validation details would be helpful.

@haileymck
haileymck merged commit a077b01 into dotnet:main Sep 21, 2026
16 checks passed
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.

[Blazor] CRUD scaffolder improvements: Support persistent component state on the scaffolder

2 participants