I found a solution using Blazor components
How to Pass Parameters in Blazor
Hi,
how can I use something like CommandParameter in Xamarin, but in Blazor
for example:
<div x-index="3" y-index="2"/>
Then access them programmaticaly in C#.
Thanks in advance
3 answers
Sort by: Most helpful
-
-
AgaveJoe 28,961 Reputation points
2024-12-07T12:21:02.62+00:00 I think Blazor data binding is what you need to learn.
https://zcusa.951200.xyz/en-us/aspnet/core/blazor/components/data-binding?view=aspnetcore-9.0
Using your example markup, the x-index and y-index are assigned to C# expressions. Updating the variables affects the markup attributes.
@page "/parameterex" @rendermode InteractiveWebAssembly <h3>ParameterEx</h3> <div x-index="@xIndex" y-index="@yIndex" /> <button @onclick="UpdateParamters">Update</button> @code { private int xIndex = 3; private int yIndex = 2; private void UpdateParamters() { xIndex = xIndex * 2; yIndex = yIndex * 2; } }
-
Bruce (SqlWork.com) 68,716 Reputation points
2024-12-09T16:53:29.57+00:00 in Blazor you use a lambda expression to pass the parameter(s) by closure.
<button @onclick="() => MyCallback(myparam1)">Click me</button>
note: the click event is captured by javascript and sent to the Blazor app via jsinterop, so no additional parameters are supported at the event level.