在Blazor中,每个页面都有一个_Layout.cshtml,而且每个页面只能使用一个_Layout.cshtml文件。然而,可以通过使用组件实现多个布局。
示例代码:
@inherits LayoutComponentBase
// Default layout contents go here
@Body
@inherits LayoutComponentBase
// Alternate layout contents go here
@Body
@page "/"
This page uses the Default layout
@layout typeof(DefaultLayout)
// Page contents go here
@page "/other"
This page uses the Alternate layout
@layout typeof(AlternateLayout)
// Page contents go here
通过使用以上方法,你可以在Blazor中实现多个自定义布局。
下一篇:Blazor字段得到null