-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor generated onclick events on loop do not work #13427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You're not using the correct syntax, mind the "@" sign before <p><button @onclick="@(_ => tstmethod("tt"))">test method</button></p> or @for (int i = 0; i < 5; i++)
{
<p><button @onclick="@(new Action(() => tstmethod(i.ToString())))">test method</button></p>
} |
In addition to @vertonghenb comment you also need to capture the variable inside the loop.
https://github.com/aspnet/Blazor/issues/275#issuecomment-373686979 This is documented here: https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.0#lambda-expressions Other issues: |
@vertonghenb your solution solved the problem. @vertonghenb yes, we do need to assign the loop value to another variable:
There was probably some change in the later version, it would be useful if the at sign had some additional coloring to it. |
@huto1 there is a coloring see the following test: |
@vertonghenb It used to be green like that, but not anymore. |
the bellow one works perfectly.
<p><button onclick="@(new Action(() => tstmethod("tt")))">test method</button></p>
And this one does not work, which is a big issue. If this does not work, there is no way to do any kind of list output.
method being used:
Is there any way to accomplish this? Or will it only be fixed in the next version?
The text was updated successfully, but these errors were encountered: