0

Consider a scenario where you have a dynamic navigation (a list of cheese categories, let's say). The navigation component exists on the layout, which has various other content components. One of those allows the user to update the name of the selected cheese category. But...how do we reflect that back on the navigation component? If one viewed it as a tree you'd have to navigate (in code) up to the layout, then navigate down to the the navigation component where the state can be updated (either by querying the server, or being passed what the update is).

Paul
  • 9,409
  • 13
  • 64
  • 113

1 Answers1

2

In general the parameter flow goes downwards, i.e., from parent to child, not in the other direction, because the rendering flow goes in that direction. That's why there isn't a way to pass parameters upstream (e.g., to a layout), because then there's be no single defined render order.

SteveSanderson

Generally speaking, you cannot pass data from the embedded components to MainLayout.

However (your question is quite vague, and you should have given a more detailed depiction of the components), you may define an AppState service that can handle the states of the components involved, and enables access to state data from those components.

See this sample authored by Steve Sanderson how to implement an AppState service. It also demonstrate what I'm going to say next: https://github.com/aspnet/samples/tree/master/samples/aspnetcore/blazor

Another way to pass data from a child component to a parent component is by defining a method that may have parameters, in a parent component, and is called from a child component via event handlers.

A more specific answer can be provided if you furnish us with the outlines of your components...

Hope this helps...

enet
  • 41,195
  • 5
  • 76
  • 113