Skip to content
Tutorials Center
My learning

Topics

Lesson 41 of 41 ยท Projects and Practice

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.

You now know the core of Blazor: components, binding and events, forms, routing, services, JavaScript interop, authorization and hosting. Skills stick when you use them, so this last lesson is practical: graded exercises with solutions you can run, a checklist for the problems that trip up almost everyone, and a roadmap of what to learn next.

Blazor itself cannot run inside this tutorial, so the exercises ask you to write real Razor in your own project, and the runnable solutions are stand-ins: the underlying C# logic (pagination, rules, a tiny render-count model) that your components would call. Build the UI yourself first, then compare with the logic here.

Exercises

Work in a fresh Blazor Web App with Interactive Server rendering. Try each exercise before reading the hints.

Level 1: components and events

  1. A Counter component with a configurable step ([Parameter] int Step) and a reset button.
  2. A Rating component showing five stars; clicking a star sets the value and reports it to the parent with an EventCallback<int>.
  3. A Toggle that supports two-way binding (@bind-Checked). Hint: a Checked parameter plus CheckedChanged.

Level 2: lists, forms and routing

  1. A product list with a search box that filters as you type (@bind:event="oninput").
  2. A paged list: 5 items per page, Previous/Next buttons disabled at the ends, the page stored in the query string (?page=2).
  3. A sign-up form with EditForm: required name, valid email, password at least 8 characters, matching confirmation, and a clear success message.

Level 3: services and state

  1. A ThemeService (scoped) that holds "light" or "dark" and notifies subscribers; two components react to it.
  2. A typed HttpClient that loads a list from a minimal API and shows loading, error and empty states.
  3. Protect /settings with [Authorize] and show an "Edit" button only for the Admin role with AuthorizeView.

Level 4: put it together

  1. Extend the task board with persistence (EF Core or browser storage) and a per-column limit (maximum 3 tasks in Doing).

Runnable solution: pagination (exercise 5)

Pagination rules are easy to get wrong at the edges (empty list, last partial page, a page number from the URL that is out of range). Put them in a small class and test them.

C# Pagination logic for exercise 5

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

In the component, the [SupplyParameterFromQuery] public int Page { get; set; } property feeds Pager.Create, and the Previous/Next buttons are NavLinks (or NavigationManager.NavigateTo) that change the query string, so every page is a shareable link (see Query Strings and URL State).

Runnable solution: a render counter (debugging aid)

A frequent question is "why did my component render again?" Blazor re-renders a component after an event it handled, after a parameter change and after StateHasChanged. A render counter during development makes unwanted renders visible. This stand-in models the decision "should I re-render?" and shows why immutable parameters help.

C# Stand-in: why a component re-renders

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The real framework is a little more forgiving: it skips re-rendering when all parameters are of simple known types and unchanged, but arrays, lists and your own classes are treated as possibly changed. If you see many renders, pass stable references, avoid creating new collections in Render, and override ShouldRender only after you have measured a problem.

The debugging checklist

When something does not work, check this list top to bottom before anything exotic.

Symptom Likely cause Fix
Button click does nothing Static SSR page: no render mode, so no events Add @rendermode InteractiveServer (or use a form post)
UI does not update after async work State changed outside Blazor's event, or from another thread Call await InvokeAsync(StateHasChanged)
NullReferenceException in OnInitialized Data not loaded yet, or parameter not set Null-check, or load in OnInitializedAsync and show a loading state
Data loads twice Prerendering plus interactive phase Persist state (see Prerendering and Streaming Rendering)
JS interop throws during startup Calling JS while prerendering Move it to OnAfterRenderAsync
Two-way binding does not stick Missing @bind-Value, or changing a copy of the object Bind to the real field; use @bind:after for side effects
Memory grows on a long-running app Event subscription without Dispose Unsubscribe in Dispose or DisposeAsync
Page works locally, fails in production Proxy blocks WebSockets, or missing index.html fallback See Publishing and Deploying Blazor Apps
User sees another user's data A singleton service holding per-user state Use a scoped service (see Service Lifetimes and Scopes)
Cannot reach protected data UI hides a button but the API is open Authorize on the server

Also use the tools: the browser developer tools (network tab for HttpClient calls, console for JavaScript errors), the Blazor WebAssembly debugger in Visual Studio or VS Code, ILogger<T> in components for server-side tracing, and bUnit tests for components that keep breaking.

What to learn next

Choose one direction at a time.

  1. Data: Entity Framework Core with SQLite or PostgreSQL, migrations, and the DbContextFactory pattern that Blazor Server needs.
  2. Testing: bUnit for components, xUnit for rules, Playwright for end-to-end checks.
  3. UI libraries: MudBlazor, Radzen or Fluent UI Blazor give you data grids, dialogs and charts, plus accessible, themeable components.
  4. Real-time features: SignalR hubs for chat and live dashboards; Blazor Server already uses SignalR underneath.
  5. Performance: Virtualize for long lists, @key, ShouldRender, lazy-loaded assemblies and AOT for CPU-heavy WebAssembly code.
  6. Cross-platform: Blazor Hybrid runs the same components in .NET MAUI, WPF or Windows Forms desktop and mobile apps.
  7. Architecture: clean separation of rules, services and UI; feature folders; the ASP.NET Core Identity and OpenID Connect stack for sign-in.
  8. Related tracks on this site: the C# tutorial for language depth, the ASP.NET Core tutorial for the server side and the JavaScript tutorial for the interop side.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A button on a page has an @onclick handler but nothing happens. The page has no @rendermode. What is the most likely cause?

    Without an interactive render mode, components render once as HTML and events are not wired up.
  2. 2. Why clamp the page number from the query string?

    Input from the URL is untrusted; clamping keeps the page valid.
  3. 3. What should you do before overriding ShouldRender?

    Blazor's diffing is cheap; optimize only when a measurement shows a problem.
  4. 4. Which problem does a singleton service holding user data cause?

    A singleton exists once per application, so per-user state belongs in a scoped service.

Summary

  • Practice with graded exercises, and keep the rules in plain C# classes that you can test.
  • Never trust values from the URL or the client; clamp, validate and authorize on the server.
  • Most "Blazor bugs" are render-mode, lifecycle, lifetime or deployment issues; use the checklist.
  • Pick one next direction: data, testing, a UI library, real-time, performance, Hybrid or architecture.

You have finished the Blazor tutorial. Return to the Blazor track page to revisit any lesson, or start the next project.

Next: Blazor track