Blazor how to pass arguments to onclick function?

前端 未结 4 1526
执笔经年
执笔经年 2021-02-03 16:55

I\'d want to make button onclick function that takes some input.



@functions
{
    pu         


        
相关标签:
4条回答
  • 2021-02-03 17:23

    At Sign on onclick specifies it's a C# function:

    @onclick = "@(() => test(i, 5*i))"
    
    0 讨论(0)
  • 2021-02-03 17:24
    <input type="button" @onclick="@(() => functionname(paramvalue))" class="....." value="DoSomething" />
    
    0 讨论(0)
  • 2021-02-03 17:37

    Try it with a lambda. You're binding the onclick to the result of the function rather than the function itself.

    @for (int i = 0; i < 10; i++)
    {
        var buttonNumber = i;
        <button @onclick="@(e => test(buttonNumber, 5 * buttonNumber))">Check</button>
    }
    
    0 讨论(0)
  • 2021-02-03 17:41

    I try this and worked

    @onclick="(() => FunctionName(argument))
    

    like

    @onclick="(() => GetDetail(item.UserId))
    

    Got idea from https://github.com/aspnet/AspNetCore/issues/15956 .

    0 讨论(0)
提交回复
热议问题