Blazor Interview Questions
Answers written to be said out loud in an interview — each with a common follow-up question and a link to the tutorial that explains it in depth.
- Beginner
- 7
- Intermediate
- 11
- Experienced
- 7
01What is Blazor?Beginner
A .NET framework for building interactive web UI with C# and Razor components instead of JavaScript. Components can render on the server or run in the browser via WebAssembly.
02How do component parameters work?Beginner
Public properties marked [Parameter] receive values from the parent component. [EditorRequired] warns when a required parameter is missing, and EventCallback parameters let children notify parents.
03What is a Razor component?Beginner
A .razor file that combines HTML markup with C# in an @code block. It renders UI, handles events and can be reused with parameters, like <ProductCard Product="p" />. Components can be pages (with @page) or building blocks.
04How do event handlers work in Blazor?Beginner
Use @onclick, @onchange, @onsubmit and so on with a C# method or lambda: @onclick="Save" or @onclick="() => Remove(item.Id)". Handlers can be async Task, and Blazor re-renders the component after they finish.
05What is @bind?Beginner
Two-way data binding between an input and a field or property: <input @bind="Name" />. It updates on change by default; use @bind:event="oninput" for every keystroke and @bind:after to run code after an update.
06How does routing work in Blazor?Beginner
@page "/products/{Id:int}" makes a component routable, and route parameters bind to [Parameter] properties. NavLink highlights the active link and NavigationManager.NavigateTo navigates in code.
07What are layouts in Blazor?Beginner
Components that inherit LayoutComponentBase and render @Body. MainLayout is set in Routes.razor; a page can choose another with @layout AdminLayout.
08Explain the Blazor Web App render modes.Intermediate
Static SSR renders HTML without interactivity. Interactive Server handles events on the server over SignalR. Interactive WebAssembly runs .NET in the browser. Interactive Auto starts on the server and switches to WebAssembly once it is downloaded.
09How do you build validated forms in Blazor?Intermediate
Use EditForm with a model, DataAnnotationsValidator, input components such as InputText, and ValidationMessage. Handle OnValidSubmit to save.
10How do components share state?Intermediate
Through parameters and EventCallbacks for parent/child, cascading values for a subtree, or a scoped/singleton state service injected with DI that raises change events.
11What is JavaScript interop?Intermediate
IJSRuntime.InvokeAsync calls JavaScript functions from C#, and [JSInvokable] methods let JavaScript call .NET. Use it for browser APIs Blazor doesn’t wrap, such as clipboard or charts.
12What is static server-side rendering (static SSR)?Intermediate
The default render mode in a Blazor Web App: components render to HTML on the server per request, with no persistent connection or WebAssembly. Forms post back normally, and enhanced navigation swaps page content without full reloads.
13What are the trade-offs of Interactive Server?Intermediate
Fast first load and full server access, but every UI event goes over a SignalR circuit, so latency affects responsiveness, each user holds server memory and the app stops working when the connection drops.
14What are the trade-offs of WebAssembly?Intermediate
The .NET runtime and your app download to the browser, so the first load is heavier, but then the UI runs client-side with no server round trips and can work offline. The code is public — it cannot hold secrets or access the database directly.
15How do you inject services into components?Intermediate
Use @inject IProductService Products in markup or [Inject] on a property in code-behind. Register services in Program.cs. Scoped services live per circuit in Interactive Server and per app in WebAssembly.
16How do you call a REST API from Blazor WebAssembly?Intermediate
Inject HttpClient (configured with the API base address) and use GetFromJsonAsync<T>, PostAsJsonAsync and so on. Handle loading and errors, and add a DelegatingHandler to attach access tokens.
@inject HttpClient Http
@if (products is null) { <p>Loading…</p> }
else { foreach (var p in products) { <p>@p.Name</p> } }
@code {
private List<ProductDto>? products;
protected override async Task OnInitializedAsync() =>
products = await Http.GetFromJsonAsync<List<ProductDto>>("api/products");
}
17How do you use EF Core safely in Blazor Server components?Intermediate
Inject IDbContextFactory<AppDbContext> and create a short-lived context per operation with await using. A single scoped DbContext would live for the whole circuit and is not thread-safe.
18How do you show content only to signed-in users?Intermediate
Wrap markup in <AuthorizeView> with <Authorized> and <NotAuthorized> sections, protect pages with @attribute [Authorize], and read the user from the cascading Task<AuthenticationState>. Enforce rules on the server too.
19How do you secure a Blazor Web App?Experienced
Use ASP.NET Core authentication, AuthorizeView and [Authorize] for UI, and always authorise on the server or API — WebAssembly code runs on the client and can be inspected or modified.
20How do you improve Blazor performance?Experienced
Use Virtualize for long lists, @key for list diffing, override ShouldRender where appropriate, avoid unnecessary re-renders from frequent events, choose render modes carefully and enable AOT/trimming for WebAssembly.
21What is the component lifecycle?Experienced
SetParametersAsync, OnInitialized{Async} (once), OnParametersSet{Async} (each time parameters change), then rendering and OnAfterRender{Async}(firstRender). Implement IDisposable or IAsyncDisposable to clean up.
22How do you handle errors in Blazor?Experienced
Use <ErrorBoundary> around risky UI to show fallback content instead of crashing the circuit, log with ILogger, and handle API failures explicitly. In Interactive Server an unhandled exception terminates the circuit.
23How do you keep state across prerendering and interactivity?Experienced
Prerendering runs OnInitializedAsync on the server and again when the component becomes interactive. Use PersistentComponentState (or the declarative [PersistentState] attribute in .NET 10) to pass the data so it is not fetched twice.
24How do you deploy a Blazor Web App?Experienced
Publish with dotnet publish -c Release and host it like any ASP.NET Core app (App Service, IIS, containers). For Interactive Server enable WebSockets and sticky sessions behind a load balancer, or use Azure SignalR Service. Standalone WebAssembly can be hosted as static files.
25How do you validate a model with custom rules in Blazor forms?Experienced
Use DataAnnotations with <DataAnnotationsValidator />, custom ValidationAttribute classes, IValidatableObject for cross-field rules, or a FluentValidation integration. Add server errors with a ValidationMessageStore after the API responds.