
Blazor uses event directives to wire up user interactions — clicks, key presses, form submissions — to C# methods.
<button @onclick="HandleClick">Click Me</button>
@code {
private void HandleClick()
{
Console.WriteLine("Button clicked!");
}
}<button @onclick="() => count++">Increment</button><input @onkeydown="HandleKey" />
@code {
private void HandleKey(KeyboardEventArgs e)
{
if (e.Key == "Enter") SubmitForm();
}
}@onclick — mouse click@onchange — input value changed@oninput — every keystroke@onsubmit — form submission@onkeydown / @onkeyup — keyboard events@onfocus / @onblur — focus eventsprivate async Task LoadDataAsync()
{
data = await Http.GetFromJsonAsync<List<Item>>("/api/items");
}Reference:
TaskLoco™ — The Sticky Note GOAT