Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Layout to null in _Layout.cshtml

Is there a reason why you would want to set the Layout property to null in a _Layout.cshtml?

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.

Is there any reason why you would want to set the Layout property in _Layout.cshtml?

like image 827
J. Polfer Avatar asked Jan 09 '15 21:01

J. Polfer


2 Answers

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.

like image 65
MstfAsan Avatar answered Oct 12 '22 13:10

MstfAsan


If you want to create a partial view that will not inherit any layout from _Layout than you will use @{ Layout = null; } in the begining of your partial view.

like image 39
error505 Avatar answered Oct 12 '22 13:10

error505