Click here to Skip to main content
15,898,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been working on "https://www.codeproject.com/Articles/5264915/Explore-Blazor-WebAssembly-use-custom-style-call-e#ptwwwcicpagafwai" and have mostly got it working.

In this project is a page Working.razor which uses 4 buttons to call a method each with a different parameter, an example follows:
Five
I have hard coded the Generate(5) method, which makes the page do what it is built for, that is to generate dummy data for insertion into an IBM Cloudant database. So after a few modifications the whole thing works, except for those 4 buttons.

One I have tried
One
<button class="w3-button w3-large w3-amber" @onClick="Generate(1)">One</button>

which also does nothing, and a few variations on
@onClick="@(() => Generate(5))"
That last one gives the error "Cannot convert lambda expression to type 'object' because it is not a delegate type".

I would like to understand how these buttons were supposed to work and how to make a button that will successfully pass an integer to the Generate method.

What I have tried:

I posted a similar question in the article comments some time ago, no response.

This is hopeless, my button code keeps disappearing. Please see the article.
Posted
Updated 11-Aug-20 14:39pm
v2
Comments
Sandeep Mewara 11-Aug-20 15:29pm    
Have you tried:
<button onclick=@(() => Mymethod(MyParam)) />

Reference: https://github.com/dotnet/aspnetcore/issues/15956
Member 69072 11-Aug-20 20:37pm    
Almost. There were two problems, I had an upper case c in onclick was my mistake. The syntax error was in the original. Yours is missing an @ sign.
``` One```
Sandeep Mewara 12-Aug-20 1:21am    
Good to know its resolved!

1 solution

```
<button class="w3-button w3-large w3-amber" @onclick = "@(() => Generate(1))">One</button>
```
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900