0

I have a question. I know how to send parameters from one component to another through url, but how could I send a parameter through one method and receive it in another?

in my first component I have the following button that executes a method in which I have a property of type bool, that property is the one that I want to send to another component

<button class="btn btn-primary" @onclick="ClickCallback">Enviar Parametro</button>

@code{
  public bool Filtro = false;

    void ClickCallback()
    {
        Filtro = true;
        Console.WriteLine(Filtro);
    }
}

and in my second component I want to receive it in this way to later use it:

[Parameter]
    public bool Filtro{ get; set; }

but I don't know how to send and receive it, I repeat I know how to pass that bool by url but I would like to pass it inside a method executed by means of a button, any suggestion? I don't know if using eventcallback I could do

Jasiel Torres
  • 383
  • 8
  • 18
  • Is one component nested in another or they are independent? – Eugene Apr 27 '22 at 18:42
  • they are independent, I am not passing the parameter from parent to child – Jasiel Torres Apr 27 '22 at 18:44
  • You can pass the parameter into both components from some parent component (parent for both) and update the value using two-way binding. The second option could be Redux pattern for Blazor to keep the state – Eugene Apr 27 '22 at 18:52
  • Check this out https://stackoverflow.com/questions/67495931/options-for-state-management-in-blazor – Eugene Apr 27 '22 at 18:53
  • Blazor is a kind of "framework ?" which let programmers to use C# to write client codes, which are usuually written by javascript before. And using blazor here will finally turn C# code to js code. They don't have many differences. So how we pass parameter data from one page to another page in js? We say that we pass the data alone with the url(page to page through get request), we say we had a global variable over the 2 pages then we set the value to that global value, we say we may store data as a cookie... I think you can understand what I write here... – Tiny Wang Apr 28 '22 at 02:37
  • If you want to receive Filtro as [Parameter] in second component then its possible only if you send it from your HTML in first component, alternatively you can have a public method in second component and have second component's @ref in first component and call that method in second component using this ref – Surinder Singh Apr 28 '22 at 03:41

0 Answers0