Categories : ASP.NET Core
Author : Date : Mar 1, 2022
Tags : asp.net core, Blazor, event handling
This article is to explain how event handling works in Blazor. The @on{event} attribute in Razor is the event handling attribute. The {event} may be any event. For example, For button @onclick is a click event. In checkbox @onchange is a change event it will trigger, when checking or unchecking the checkbox.
The following is an example for @onclick. In this code, the @page directive is added for routing. Then @result property value is added to display the result. Then the @onclick attribute is added to the button and the DisplayMessage method is assigned to it. When the user clicks the button it will display the message.
The following is an output of the above code.
You can achieve the same result as above using lambda expressions.
Also, you can pass arguments to the @onclick method using the Lambda expression.
The following code explains how to pass arguments. Here in GetSum() method two arguments a and b are passed.
The following is an output of the above code.
This article explains what is event handling in Blazor and how to pass parameters to an event handler.
If you have questions, please leave your comments.