Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple counter component using Blazor WebAssembly with Razor syntax and C# for interactivity.
@page "/counter"
<h3>Counter</h3>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">+</button>
<button class="btn btn-danger" @onclick="DecrementCount">-</button>
<button class="btn btn-secondary" @onclick="ResetCount">Reset</button>
<button class="btn btn-warning" @onclick="ToggleTheme">Switch Theme</button>
@code {
private int currentCount = 0
private bool isDark = false
private void IncrementCount() => currentCount++
private void DecrementCount() => currentCount--
private void ResetCount() => currentCount = 0
private void ToggleTheme() {
isDark = !isDark
var body = document.body
if (isDark) body.classList.add("dark-theme")
else body.classList.remove("dark-theme")
}
}Blazor is a Microsoft framework for building interactive web applications using C# and .NET, running client-side via WebAssembly or server-side via SignalR.
Origin & Creator
Blazor was created by Microsoft in 2018 to bring C# and .NET development to web browsers without requiring JavaScript.
Industrial Note
Blazor is primarily used in enterprise .NET ecosystems for full-stack C# development, reducing reliance on JavaScript and enabling shared code across client and server.