Blazor provides support for event handling of HTML element by referring a pointer to the function that is used to handle the event, For handling @onclick event of the HTML element, define a function/method in the @code section and then refer the delegate typed value to the @onclick attribute of the HTML element.
Refer to the following code sample.
<button class="btn btn-primary" @onclick="ButtonClick">Click</button>
@code {
private void ButtonClick(MouseEventArgs args){
Console.WriteLine(“ButtonClicked”)
}
}
Here, the ButtonClick is the event handler function (delegate typed value) assigned to @onclick of the button (HTML element).
Share with