Blazor components and render modes
Blazor components and render modes
Blazor renders user interfaces from Razor components: reusable units of markup and C# behavior. In a Blazor Web App, render modes determine where component code runs and whether event handlers remain interactive after the initial HTML arrives.
Static SSR creates HTML on the server for a request without establishing interactive component state. Interactive Server keeps component state on the server and exchanges UI events and updates over a circuit. Interactive WebAssembly runs interactive component code in the browser after the client runtime loads; server access must use an API. Interactive Auto can use server interactivity initially and client interactivity on subsequent visits after the client bundle is available; it does not migrate a running component instance automatically. Interactive modes normally prerender by default. Rendering and authorization are distinct: a disabled button does not protect a server operation. The local projects configure only server interactivity; WebAssembly and Auto require a compatible client project and are discussed, not implemented here. A component with a parameter receives data from its parent; a callback can communicate an event back. Avoid passing nonserializable values across static-to-interactive boundaries. The examples below are separate full projects; run one at a time, navigate to http://localhost:5087/ and stop with Ctrl+C. Browser results are predicted, not observed.
Baseline: .NET 10 / C# 14. In an approved environment use the complete fixture project, restore only reviewed dependencies from approved sources, then run dotnet build --no-restore and dotnet run --no-build --no-launch-profile. Blazor projects use localhost:5087; stop the server with Ctrl+C. Other examples start a bounded local server and client in one process. No real credentials or external services. Expected results are reasoned, not executed.
Render a static catalog card
Inspect the initial HTML; no interactive mode is selected.
using Fixture;var builder = WebApplication.CreateBuilder(args);builder.WebHost.ConfigureKestrel(o => o.ListenLocalhost(5087));builder.Services.AddRazorComponents().AddInteractiveServerComponents();var app = builder.Build();app.UseAntiforgery();app.MapStaticAssets();app.MapRazorComponents<App>().AddInteractiveServerRenderMode();app.Run();App.razor
@using Microsoft.AspNetCore.Components.Routing<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><base href="/" /><title>ByteMind local lab</title></head><body><main><Router AppAssembly="typeof(App).Assembly"><Found Context="route"><RouteView RouteData="route" /></Found></Router></main><script src="_framework/blazor.web.js"></script></body></html>Demo.razor
@page "/"@using Microsoft.AspNetCore.Components@using Microsoft.AspNetCore.Components.Web@using Microsoft.AspNetCore.Components.Forms@using static Microsoft.AspNetCore.Components.Web.RenderMode<h1>Catalog</h1><p>Available: @stock</p>@code { private int stock = 4; }Expected result (not executed):
Initial page: Catalog; Available: 4.This page needs no persistent circuit for its text.
Handle an interactive button
Wait for the connection and then click the native button twice.
using Fixture;var builder = WebApplication.CreateBuilder(args);builder.WebHost.ConfigureKestrel(o => o.ListenLocalhost(5087));builder.Services.AddRazorComponents().AddInteractiveServerComponents();var app = builder.Build();app.UseAntiforgery();app.MapStaticAssets();app.MapRazorComponents<App>().AddInteractiveServerRenderMode();app.Run();App.razor
@using Microsoft.AspNetCore.Components.Routing<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><base href="/" /><title>ByteMind local lab</title></head><body><main><Router AppAssembly="typeof(App).Assembly"><Found Context="route"><RouteView RouteData="route" /></Found></Router></main><script src="_framework/blazor.web.js"></script></body></html>Demo.razor
@page "/"@using Microsoft.AspNetCore.Components@using Microsoft.AspNetCore.Components.Web@using Microsoft.AspNetCore.Components.Forms@using static Microsoft.AspNetCore.Components.Web.RenderMode@rendermode InteractiveServer<h1>Stock preview</h1><p role="status">Selected: @selected</p><button type="button" @onclick="Add">Add one</button>@code { private int selected; private void Add() => selected++; }Expected result (not executed):
Selected: 0 initially; Selected: 2 after two clicks.The server-side event changes component state, and Blazor sends a rendered update.
Reuse a parameterized component
Pass two different values from the parent page.
using Fixture;var builder = WebApplication.CreateBuilder(args);builder.WebHost.ConfigureKestrel(o => o.ListenLocalhost(5087));builder.Services.AddRazorComponents().AddInteractiveServerComponents();var app = builder.Build();app.UseAntiforgery();app.MapStaticAssets();app.MapRazorComponents<App>().AddInteractiveServerRenderMode();app.Run();App.razor
@using Microsoft.AspNetCore.Components.Routing<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><base href="/" /><title>ByteMind local lab</title></head><body><main><Router AppAssembly="typeof(App).Assembly"><Found Context="route"><RouteView RouteData="route" /></Found></Router></main><script src="_framework/blazor.web.js"></script></body></html>Demo.razor
@page "/"@using Microsoft.AspNetCore.Components@using Microsoft.AspNetCore.Components.Web@using Microsoft.AspNetCore.Components.Forms@using static Microsoft.AspNetCore.Components.Web.RenderMode@rendermode InteractiveServer<h1>Locations</h1><StockCard Label="North" Count="3" /><StockCard Label="South" Count="0" />StockCard.razor
@using Microsoft.AspNetCore.Components<p>@Label: @Count</p>@code { [Parameter] public string Label { get; set; } = ""; [Parameter] public int Count { get; set; }}Expected result (not executed):
North: 3; South: 0.Each child has its own parameter values. The parent owns the input.
Apply the concept
Choose a mode for an informational help page, an interactive internal dashboard and a browser-only offline calculator. State the required hosting and API boundaries.
Use the manual practice and knowledge check to reason about the boundary. Do not deploy these local demonstrations as production services.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Blazor components and render modes — knowledge check
Apply the lesson concepts to the following scenarios.
Which mode can render a request without persistent interactive component state?
Where does an Interactive Server click handler execute?
Does Auto move a currently running component to the browser automatically?
What normally occurs before an interactive component activates?
Can a hidden button enforce data access?