相关疑难解决方法(0)

blazor 变量参数传递给 onclick 函数

我想将 int i 传递给每个列表项的按钮 onclick 函数。我预计“clickItem”函数将收到 0..2 对应的列表项。但结果是它总是接收 3 作为参数。似乎 clickItem(i) 中的变量 i 在 for 循环的渲染时没有被评估。我曾尝试将其更改为“clickItem(@i)”,但它仍然相同。我该怎么办?(我使用 blazor 服务器端,.net core 3 preview 5)

        @for (int i = 0; i < 3; i++)
        {
            <li> item @i <button onclick=@(() => clickItem(i))>Click</button> </li>
        }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

blazor blazor-server-side

5
推荐指数
1
解决办法
3319
查看次数

从Blazor中生成的按钮调用功能

I'm currently trying to call a method from some autogenerated buttons, that are set up from some configuration. So the number of buttons is configurable. I have the blazor page as shown below. My problem is that if I have 3 buttons and I press one then ButtonClicked is called correctly, but the index is always 3 - the end value of int i for the for-statement. I of course want the index of the button to be passed …

c# asp.net-core blazor

2
推荐指数
1
解决办法
644
查看次数

标签 统计

blazor ×2

asp.net-core ×1

blazor-server-side ×1

c# ×1