Blazor is Microsoft's framework for building interactive web UIs using C# instead of JavaScript, part of the ASP.NET Core stack. It's the #18 most-used web framework, reported in roughly 7% of developer surveys. Components can run either in the browser via WebAssembly (Blazor WebAssembly) or on the server with UI updates streamed over SignalR (Blazor Server), which makes it the natural choice for .NET shops that want to build modern, componentized web front ends without leaving the C# ecosystem.
A Blazor component is a `.razor` file that mixes HTML markup with C# logic in an `@code` block, using data binding directives like `@onclick` and `@bind`.
@* Counter.razor *@
<h3>Counter</h3>
<p>Current count: @count</p>
<button class="btn btn-primary" @onclick="IncrementCount">
Click me
</button>
@code {
private int count = 0;
private void IncrementCount()
{
count++;
}
}
Scaffold a new Blazor project with the .NET CLI, choosing either the WebAssembly or Server hosting model.
# create a new Blazor WebAssembly project
dotnet new blazorwasm -o MyBlazorApp
cd MyBlazorApp
dotnet run