Introduction
Blazor is a web framework developed by Microsoft that allows developers to build interactive web applications using C# instead of JavaScript. It is part of the .NET ecosystem, making it possible to run C# code directly in the browser with the help of WebAssembly, or on the server with a real-time connection. This cheatsheet is a quick guide to the most critical Blazor features, syntax, and usage examples.
Blazor Hosting Models
Blazor Server
Runs on the server.
Uses SignalR to update UI.
Small download size.
Example
@page "/counter" <h3>Counter</h3> <p>Count: @count</p> <button @onclick="Increment">Click</button> @code { private int count = 0; private void Increment() => count++; }Important: Faster load, but requires a constant connection.
Blazor WebAssembly
Runs in the browser.
Uses WebAssembly to execute .NET code.
Larger download size.
Important: Works offline after first load.
Components
Small building blocks of UI.
Written in .razor files.
Example
@code { [Parameter] public string Title { get; set; } } <h3>@Title</h3>Important: Use [Parameter] for parent-to-child data.
Data Binding
1. One-way binding
<p>Hello, @name</p>
@code {
string name = "Rinki";
}
Data flows from code to UI.
2. Two-way binding
<input @bind="name" />
<p>@name</p>
@code {
string name = "Rinki";
}
Data syncs between UI and code.
Event Handling
Use @on... attributes.
Example
<button @onclick="ShowMessage">Click</button> @code { void ShowMessage() => Console.WriteLine("Clicked!"); }
Lifecycle Methods
Special methods that control component behavior.
Common ones
protected override void OnInitialized() { } protected override void OnParametersSet() { } protected override async Task OnAfterRenderAsync(bool firstRender) { }Important
OnInitialized: Runs when the component is created.
OnParametersSet: Runs when the parent sends new data.
OnAfterRenderAsync: Runs after rendering UI.

Join the conversation! Your thoughts help the community grow.