Call the Button OnClick method generically?

perfect code 276 Reputation points
2023-03-05T10:58:23.2+00:00

Is it possible to call the Button OnClick method generically?

I have tried the following, unfortunately nothing has worked:

<Button Type="primary" OnClick="() => OnClick_Reload<CustomerModel>()" />

<Button Type="primary" OnClick="OnClick_Reload<CustomerModel>" />

Thanks

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,666 Reputation points
    2023-03-05T14:00:13.9366667+00:00

    Lambda expressions are supported as the delegate event handler.

    See the example:

    <h1>@heading</h1>
    <button @onclick="@(e => heading = "New heading!!!")">
            Update heading
        </button>
    

    Refer the sample in the link: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/event-handling?view=aspnetcore-7.0#lambda-expressions

    Hope this helps

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.