在_Layout.cshtml中将Layout设置为null [英] Setting Layout to null in _Layout.cshtml
问题描述
您是否有理由要在_Layout.cshtml中将Layout属性设置为null?
例如,像这样,在渲染主体视图之前?
For example, like this, before rendering the body view?
...
<section id="content">
@{ Layout = null; }
@RenderBody()
</section>
...
对我来说似乎很荒谬,删除行设置不会改变页面加载的工作方式.
It seems pretty nonsensical to me, and removing the line setting Layout doesn't change the way page loads work observationally.
是否有任何原因,您为什么要在_Layout.cshtml中设置Layout属性?
Is there any reason why you would want to set the Layout property in _Layout.cshtml?
推荐答案
布局页面也可以具有布局.在嵌套布局中,您有意使用 Layout 属性定义布局页面的超级布局.默认情况下,如果未指定,则在布局页面中为null.当您制作 @ {Layout = null}
时,您明确地说这是您的最终布局,因此它不嵌套在任何超级布局中.
Layout pages can have a layout too. In nested layouts , you intentionally use Layout property to define super layout of layout page . By default it is null in your layout page if you do not specify any. When you make @{Layout=null}
you are explicitly saying that this your final layout so it is not nested in any super layout.
这篇关于在_Layout.cshtml中将Layout设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!