Skip to content

Is it possible to use @layout with serverside Blazor components? #25861

Discussion options

You must be logged in to vote

You can do this but you'll need to use the <LayoutView> component (or a <Router>), because that's what causes the Blazor component's layout to be rendered.

For example, if your .cshtml file renders MyHost.razor, containing:

<LayoutView Layout="@typeof(MainLayout)">
    <SomeOtherComponent />
</LayoutView>

... then this will render SomeOtherComponent inside the MainLayout layout. Using this approach you don't even need to put a @layout attribute on your page.

Alternatively inside MyHost.razor you could render a Blazor <Router> component. This would then take case of picking which other component to render based on the URL and your @page attributes, plus it automatically picks whichever lay…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SteveSandersonMS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants