Interactive parts on static pages
Most of a page can stay static. Give a render mode to the one component that needs C# to answer the user, and the rest of the page still loads and scales like a web page.
What stays static
IzzyBlazor's components respond in the browser on static pages: dialogs and tabs open, tables sort and filter
through the URL, and a Combobox with Search asks the server as the user types.
Render modes lists what each component does on static pages
and where a static page stores its state. Two more things need no interactive part:
- Saving a form. A Form posts, and the server validates the model.
- Data that takes a while to load. With
[StreamRendering], the server sends the page first and the data when it's ready. See Microsoft's Streaming rendering (opens in a new tab).
A render mode on one component
When one part of a page does need C# between requests, put the render mode on that component, not on the page:
"/orders/{Id:int}"
<PageHeader Title="Order" />
<OrderDetails Id="Id" />
<OrderChat OrderId="Id" @rendermode="InteractiveServer" />
{
[Parameter] public int Id { get; set; }
}- Pass simple values in. Parameters cross from the static page as JSON, so pass an id, a string or a small record. Content between the component's tags can't cross, and neither can a callback. The interactive component loads its own data from the id.
- Everything inside it is interactive. A component's children run in its render mode. Keep the interactive part small, and leave the page's header, navigation and details outside it.
- A browser part lives in the client project. A component with
InteractiveWebAssemblyorInteractiveAutogoes in the.Clientproject, and loads its data through a client store. - Leave the app's render mode unset. This works when
Routeshas no render mode of its own. In an app that is interactive throughout, a page opts out with[ExcludeFromInteractiveRouting], andApp.razorleaves the render mode off for it, as the sign-in pages do.
See Microsoft's ASP.NET Core Blazor render modes (opens in a new tab) for what a render mode can be applied to and what parameters it accepts.
The two halves share the request
A static component can't call an interactive one, and the interactive one can't re-render the static page around it. They share what a request carries:
- The URL. The interactive part navigates to change a value in the URL, and the server renders the static parts for the new URL.
- The database. The interactive part saves, and the static parts read the saved rows on the next request.
- A cookie. For a preference both halves read, such as a layout the user chose.
Navigation and form posts without a full reload
Blazor's script runs on static pages too. It fetches the next page and swaps in what changed, so a link
doesn't reload the browser tab. Neither does a form post from IzzyBlazor's Form, which turns
this on by default; a plain <form> needs data-enhance. None of this needs a
circuit. See Microsoft's
Enhanced navigation and form handling (opens in a new tab).
When a circuit is worth it
| The part | Why it's interactive |
|---|---|
| A chat, a feed or a dashboard that updates by itself | The server pushes changes to the page with no request from the user. |
| An editor where each change recalculates others | C# runs on every change, faster than a post per change. |
| A wizard whose steps depend on unsaved answers | The state lives in memory until the last step saves it. |
| A grid edited cell by cell, with selection and bulk actions | Many small C# events on one screen. |
The circuit opens when the page's first Interactive Server component starts, and closes when none remain. A page with none has no circuit. So the cost follows the pages that need it, not the whole app.
Next steps
- Render modes: what each render mode is, and what components do in each.
- What each render mode adds: what a whole page costs in each render mode.
- Data access by render mode: how each half of the page loads its data.
- Session recovery: what an interactive part does when its connection drops.