Catalog / Blazor Cheat Sheet
Blazor Cheat Sheet
A quick reference guide for Blazor, covering components, data binding, routing, and other essential concepts for building interactive web UIs with C#.
Component Basics
Component Definition
Blazor components are reusable UI elements written in C# and HTML (Razor syntax). Example:
|
Components can receive data through parameters. Use the |
Lifecycle Methods
|
Called when the component is initialized, after parameters are set. |
|
Called after the component receives parameters from its parent. |
|
Called after the component has been rendered. Use |
|
Allows you to control when a component should re-render. Return |
|
Called when the component is being disposed. Use this to unsubscribe from events and release resources. |
Event Handling
Blazor uses standard C# event handling. Example:
|
Use |
Data Binding
One-Way Binding
Displaying data from a C# variable in the UI. Example:
|
Two-Way Binding
Allows updating a C# variable when the UI element changes. Example:
|
|
Binding with different event
|
Routing
Page Directive
Defines the route for a component, making it accessible via a URL. Example:
|
Use |
Route Parameters
Pass data to a component through the URL. Example:
|
Use |
Navigation
Programmatically navigate between pages using Example:
|
Inject |
Dependency Injection
Service Registration
Register services in Example:
|
Use |
Service Injection
Inject services into components using the Example:
|
Use |