Advertisement
Advanced ASP.NET Core, Blazor Integration with ASP.NET Core

How does prerendering work when a Blazor component is embedded within a traditional Razor Pages or MVC view, and what is the purpose of Component Tag Helpers?

Short answer

The tag helper (render-mode="ServerPrerendered" or similar) lets you embed an interactive Blazor component directly within an otherwise traditional server-rendered Razor Page or MVC view, rendering the component's initial HTML on the server as part of the page response (so users…

Save ASP.NET Core mock interview
Advertisement
AModel answer
The <component> tag helper (render-mode="ServerPrerendered" or similar) lets you embed an interactive Blazor component directly within an otherwise traditional server-rendered Razor Page or MVC view, rendering the component's initial HTML on the server as part of the page response (so users see content immediately), then 'hydrating' it into a fully interactive component once the client-side runtime (SignalR connection or WASM) initializes -- letting teams add small pockets of Blazor interactivity to an existing traditional application without a full rewrite.
<!-- Inside a traditional Razor Page (.cshtml) -->
<component type="typeof(WeatherWidget)" render-mode="ServerPrerendered" />

<!-- WeatherWidget.razor renders its initial HTML immediately,
     then becomes fully interactive after the SignalR connection establishes -->
Real-world example
A legacy MVC e-commerce site adds a small interactive 'live inventory count' Blazor component embedded within an existing traditional product detail Razor view, incrementally introducing Blazor without rewriting the entire page.
Likely follow-ups
  • What issues can arise if component code isn't safe to run twice (prerender phase and real render phase)?
  • How does this differ from the newer unified .razor-component-only hosting model in .NET 8+?
Related topics