How to execute async method on button click in Blazor?

Platform: Blazor|Category: Event handling

In Blazor, all native events are bound to async task. You can bind the button click event with async task handler. In the following example, the button click event bound to async method.

<button @onclick="@onClick"> Click </button>

@code {

    private async Task onClick()
    {
        await service.GetItems();
    }
}