Blazor Tutorial
Learn Blazor step by step: 41 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Blazor? Learn what Blazor is, how it lets you build interactive web UIs in C# instead of JavaScript, how components work, and how it compares with React, Angular and Razor Pages in .NET 10.
- Setting Up and Project Structure Install the .NET SDK, create a Blazor Web App with dotnet new, and learn what Program.cs, App.razor, Routes.razor, the Components folder and wwwroot do in a Blazor project.
- Your First Blazor Component Build your first Blazor component step by step: the @page directive, markup, the @code block, an @onclick handler, reusing a component as a tag, and how the Counter template page works.
- How Blazor Renders and Updates the UI Understand the Blazor render tree, how diffing produces minimal DOM updates, when components re-render, how @key keeps list items stable, and how to avoid needless renders with ShouldRender.
- Debugging and Hot Reload Learn how to run a Blazor app with dotnet watch, use Hot Reload, set breakpoints, read browser console errors, log with ILogger and spot the mistakes beginners make most often.
Components and Razor Syntax
- Razor Syntax Basics Learn Razor syntax for Blazor components: @ expressions, implicit and explicit expressions, code blocks, directives like @using and @inject, escaping the @ symbol, comments and raw HTML.
- Component Parameters Pass data into Blazor components with [Parameter]: required parameters, defaults, passing C# expressions, CaptureUnmatchedValues, route parameters, and why parameters should not be changed from inside.
- Child Content and Render Fragments Build wrapper and templated components in Blazor with ChildContent, RenderFragment, RenderFragment of T, named fragments and generic components using @typeparam, with runnable C# stand-ins.
- Component Lifecycle Methods Learn the Blazor component lifecycle: SetParametersAsync, OnInitializedAsync, OnParametersSet, OnAfterRender, ShouldRender and IDisposable, with the right place to load data and clean up.
- Conditionals and Loops in Razor Render dynamic Blazor UI with @if, @else, @switch, @foreach and @for: show loading and empty states, build lists and tables, use CSS classes conditionally, and avoid closure bugs in loops.
Data Binding and Events
- Event Handling in Blazor Handle user events in Blazor with @onclick, @oninput, @onkeydown and @onsubmit: event argument types, lambda handlers, async handlers, preventDefault, stopPropagation and common event pitfalls.
- Two-Way Data Binding with @bind Learn Blazor two-way data binding with @bind for text boxes, checkboxes, selects and radio buttons, what it expands to (value plus onchange), and how to bind to properties and component parameters.
- Binding Formats, Events and Modifiers Fine-tune Blazor data binding with @bind:event for live updates, @bind:format and culture for dates and numbers, @bind:after and @bind:get/@bind:set for side effects, plus debouncing typed input.
- Event Callbacks and Component Communication Learn how Blazor child components talk to parents with EventCallback and EventCallback of T, why it beats Action and Func, how to build reusable buttons and list items, and how to avoid prop drilling.
- Component References and StateHasChanged Learn when Blazor needs StateHasChanged, how InvokeAsync marshals work onto the UI thread, how to update from timers and background tasks, and how @ref gives you element and component references.
Forms and Validation
- EditForm Basics Learn the Blazor EditForm component: binding a model, EditContext, OnSubmit versus OnValidSubmit and OnInvalidSubmit, form names for static rendering, and how a submit flows through the form.
- Input Components Use Blazor's built-in input components: InputText, InputNumber, InputDate, InputCheckbox, InputSelect, InputRadioGroup and InputTextArea, with type conversion, formats, CSS classes and extra attributes.
- Validation with Data Annotations Validate Blazor forms with Data Annotations: Required, StringLength, Range, RegularExpression, EmailAddress, Compare, ErrorMessage, DataAnnotationsValidator, ValidationMessage and ValidationSummary.
- Custom Validation and Validation UI Write custom validation for Blazor forms: custom ValidationAttribute classes, IValidatableObject for cross-field rules, ValidationMessageStore for server errors, and styling validation messages.
- File Uploads and InputFile Upload files in Blazor with InputFile: IBrowserFile, OnChange, MaxAllowedSize, OpenReadStream, multiple files, accept filters, saving to disk safely and showing upload progress.
- Form Patterns and Submit State Build robust Blazor forms: prevent double submits, show loading and success states, reset a form, warn about unsaved changes, edit existing data with a copy, and handle server errors.
Routing and Layouts
- Routing and Route Parameters Learn Blazor routing with the @page directive, route parameters, optional values, constraints, catch-all routes and how the Router picks the best match for a URL.
- Navigation, NavLink and NavigationManager Move between Blazor pages with anchors, NavLink and NavigationManager. Learn base URIs, NavigateTo options, active link matching and how to guard against leaving a page.
- Layouts and Nested Layouts Build shared page structure in Blazor with LayoutComponentBase, @Body, the @layout directive, _Imports defaults, nested layouts and sections that pages can fill.
- Query Strings and URL State Keep filters, sorting and paging in the Blazor URL with SupplyParameterFromQuery, GetUriWithQueryParameter and typed parsing, so pages can be shared, bookmarked and reloaded.
- Route Constraints and Catch-All Routes in Blazor Restrict Blazor route parameters with constraints like int and guid, accept optional values, capture whole paths with catch-all routes and build a custom not-found page.
State and Dependency Injection
- Dependency Injection in Blazor Use dependency injection in Blazor components with @inject and [Inject], register services in Program.cs, inject into services, and build a tiny container to see how it works.
- Service Lifetimes and Scopes in Blazor Understand singleton, scoped and transient services in Blazor Server and WebAssembly, how a circuit acts as a scope, captive dependencies and disposing services correctly.
- Component State and Cascading Values Learn how Blazor components keep state, when they re-render, how StateHasChanged works, and how CascadingValue and CascadingParameter share data down the component tree.
- State Containers and App State in Blazor Share state between Blazor components with a scoped state container and change events, and keep it across reloads with browser storage and PersistentComponentState.
- Calling APIs from Blazor with HttpClient Fetch and send JSON from Blazor components with HttpClient, typed clients and IHttpClientFactory, and handle loading, errors and cancellation in the UI.
JS Interop and Auth
- JavaScript Interop Basics Call JavaScript from Blazor with IJSRuntime, pass and return values, handle errors and prerendering, and know when interop is worth it. Includes a runnable C# stand-in.
- JS Modules and Calling .NET from JavaScript Load JavaScript as isolated ES modules in Blazor, call C# from JavaScript with JSInvokable and DotNetObjectReference, and dispose references so nothing leaks.
- Authentication and Authorization in Blazor Learn how Blazor knows who the user is, how AuthenticationState, AuthorizeView, the Authorize attribute and cascading state work, and how claims drive what users see.
- Policies, Roles and Claims in Blazor Protect Blazor pages and UI with roles, claims and policy-based authorization, write custom requirements and handlers, and use resource-based checks for individual records.
Hosting Models and Deployment
- Blazor Hosting Models and Render Modes Compare Blazor Server, WebAssembly, Auto and static server rendering, learn how render modes are chosen per component, and decide which model fits your app.
- Prerendering and Streaming Rendering in Blazor Understand why interactive Blazor components run twice, how to avoid duplicate data loads and flicker with persisted state, and when streaming rendering shows content sooner.
- Publishing and Deploying Blazor Apps Publish a Blazor app for production, choose between server hosting, containers and static hosting, trim and compress WebAssembly downloads, configure the environment and check health.
Projects and Practice
- Project: Build a Task Board in Blazor Build a Kanban-style task board in Blazor step by step: model and service, state container with change events, reusable components, filtering and the runnable logic.
- Project: Expense Tracker with Forms and Validation Build an expense tracker in Blazor with an EditForm, data annotations, a service layer, an HTTP-backed repository and totals by category, with runnable domain logic.
- Blazor Practice Set, Debugging Checklist and Next Steps Practice Blazor with graded exercises and runnable solutions, use a debugging checklist for the most common component problems, and plan what to learn next after the basics.