Last post Jun 14, 2019 03:06 PM by Mikesdotnetting
Jun 14, 2019 09:48 AM|Nick Whymark|LINK
I have a layout with a side nav a header and a main body. The main body can have one of x components rendered in it. I'd like the header to be contextual, so I'd like the "child" component in the body to pass a component to the layout to be rendered in the
I'm not quite sure if I can achieve this, and if so how? I could have the layout subscribe to an event on the child component but I'm not sure how to pass a component to a method and have it render, is that possible?
I'm using Blazor client side if that helps.
Jun 14, 2019 10:58 AM|Nick Whymark|LINK
I think I might be able to pass a RenderFragment back up, but I'm not quite sure how to get it to the layout component from the @body component..
Jun 14, 2019 01:06 PM|Mikesdotnetting|LINK
I'd like the header to be contextual
Jun 14, 2019 01:52 PM|Nick Whymark|LINK
Thanks for taking the time to reply. It's not impossible I'm over complicating this, but I think the question is still interesting.
The header is contextual to the component. I have a layout that has a full height nav bar on the left. And then to the right of that I have a header and underneath the body (@Body). The links in the navbar route to different components in the @Body and each
one will have "actions" (buttons/links etc) that need to be on the header. It seemed ideal for the UI layout to continue to be in MainLayout.razor, but I want to "inject" the header from the child (i.e. the component rendered in the @Body). I'm not sure how
to pass the render fragment back to the layout for rendering in the header space.
It's basically the opposite of @ChildContent which allows a parent component to pass a RenderFragment to a child component. I want to do the opposite from the @Body component to the layout.
I could just remove the header from the layout and give each component a header but this didn't seem quite right. Especially as I need to keep the header and side nav from scrolling and just have the body component scroll (which I have working).
Jun 14, 2019 03:06 PM|Mikesdotnetting|LINK
Some of the discussion in this issue might be relevant: https://github.com/aspnet/Blazor/issues/857