Set up by hand
To set up IzzyBlazor in a Blazor Web App without izzy init, follow the same steps by hand. You install
one package, link a stylesheet, add the theme and add a line to Program.cs. A .Client
project gets its own package and registration.
Install the package
Add the package to the server project:
dotnet add package IzzyBlazor --prereleaseAdd the stylesheet and the theme
Link the stylesheet before your own, and put IzzyTheme in the head:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<ResourcePreloader />
<link rel="stylesheet" href="Assets["_content/IzzyBlazor.Core/izzyblazor.css"]" />
<link rel="stylesheet" href="Assets["app.css"]" />
<link rel="stylesheet" href="Assets["MyApp.styles.css"]" />
<IzzyTheme />
<ImportMap />
<HeadOutlet />
</head>IzzyTheme sets the preset, brand color and fonts, as in
<IzzyTheme Preset="ThemePreset.Compact" Brand="#0a7d5a" />. It renders on the server, so the
theme applies on first paint, even with JavaScript off. You don't add a script tag, because Blazor loads
IzzyBlazor's script itself.
Import the components
IzzyBlazor
Use this instead of a global using. It brings the components into .razor files only, so
names such as Table and Column don't clash with EF Core's attributes in your entity
classes.
Register the services
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIzzyBlazor();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
// ...
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();AddIzzyBlazor adds the toast and dialog services, and keeps toasts across a redirect. It also lets
components read their cookies on the server, such as the cookie that stores the color scheme the user picked.
Add toasts and dialogs
To show toasts, put one ToastRegion in your layout. It works on static pages too:
LayoutComponentBase
Body
<ToastRegion />
On static pages, the ToastRegion also reads Announcer's messages to screen readers (see
LiveRegion). In a layout without toasts, add an
<AnnouncerRegion /> instead.
To open dialogs from C# with DialogService, put one <DialogHost /> on the
interactive page that opens them. Or put it in the layout and give the host a render mode:
<DialogHost @rendermode="InteractiveServer" />. Dialogs written in the page's markup don't
need a host. See Dialog.
The .Client project
With WebAssembly or Auto, components that run in the browser are in a .Client project. That project
can't use ASP.NET Core's server framework, so it gets IzzyBlazor.Core. The server project keeps
IzzyBlazor:
dotnet add MyApp.Client package IzzyBlazor.Core --prerelease IzzyBlazorusing Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddIzzyBlazorCore();
await builder.Build().RunAsync();
An Auto page renders on the server first and in the browser later, so it uses both registrations.
AddIzzyBlazor on the server includes everything AddIzzyBlazorCore adds.
App.razor always renders on the server, so you set up the stylesheet and theme only once, in the
server project.
| Package | Contains | Install in |
|---|---|---|
IzzyBlazor | Everything in IzzyBlazor.Core, plus the server code that reads and writes the request's cookies | The server project |
IzzyBlazor.Core | Every component, the CSS and IzzyBlazor's script, with no dependency on the ASP.NET Core server | The .Client project, or a Razor class library |
Every component is in IzzyBlazor.Core. Both packages use the IzzyBlazor namespace, so
the same markup works in either project. Keep both packages on the same version.
From the full template
If you created the app without --empty, the full template's styles win over IzzyBlazor's until
Bootstrap is in a layer. Its NavMenu also clashes with IzzyBlazor's. See
Keep Bootstrap and
Name clashes.
Build a first page
A form shows what static rendering does on its own:
"/signup"
System.ComponentModel.DataAnnotations
<Container Size="ContainerSize.Sm" PaddingY="8">
<Form Model="Model" FormName="signup" OnValidSubmit="Save">
<TextField @bind-Value="Model!.Email" AutoComplete="email" />
<Button Submit>Sign up</Button>
</Form>
if (_signedUp)
{
<Alert Status="Status.Success">Thanks! We'll write to Model!.Email.</Alert>
}
</Container>
{
[SupplyParameterFromForm(FormName = "signup")]
private SignupModel? Model { get; set; }
private bool _signedUp;
protected override void OnInitialized() => Model ??= new();
private void Save() => _signedUp = true;
public sealed class SignupModel
{
[Required, EmailAddress]
public string? Email { get; set; }
}
}
Run the app and open /signup. The form posts, validates and shows its message without a circuit,
even with JavaScript off. To run the same markup over a circuit, add @rendermode InteractiveServer
under @page. See Form for more.
Next steps
- AppShell: build your layout's header, sidebar and main area.
- Render modes: what components do on static and interactive pages.
- Style props: set spacing, sizes and colors on any component.