如何为特定控制器将第二个布局与父布局一起使用。 在ASP.NET MVC应用中,我们为所有视图提供了父级布局
@{
Layout = "_Layout";
}
现在我有Controller调用XcxController
,对于XcxController
的所有视图,我想与父XcxLayout
一起使用名为Layout
的另一种布局。
有可能吗?我该如何实现?
答案 0 :(得分:1)
是的,您可以使用多个嵌套版式,包括版式内的版式:
Index.cshtml:
@{
Layout = "_Layout";
}
<h1>This is normal index page</h1>
Layout.cshtml:
<h2>with normal layout</h2>
@RenderBody()
PageWithNestedLayout.cshtml:
@{
Layout = "_NestedLayout";
}
<h1>This is another page</h1>
_NestedLayout.cshtml:
@{
Layout = "_Layout";
}
<h2>with a nested layout and:</h2>
@RenderBody()