Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a view know which layout to use? Where is the default?

In default mvc app. There are Layout and content pages, You know (_Layout, Home, Contact, etc.)

And content pages do not contain layout refrence as this:

Layout = "~/Views/Shared/_Layout.cshtml";

In content pages this code is missing. But they works. How does it do this without layout refrence?

like image 333
AliRıza Adıyahşi Avatar asked Apr 18 '12 00:04

AliRıza Adıyahşi


2 Answers

Because your _ViewStart.cshtml contains a reference to the default layout that will be used when a specific one is not stated on the view.

When you want to change the layout for a single view, you would include a Layout = "..."; to that view.

like image 107
Valamas Avatar answered Nov 20 '22 06:11

Valamas


If you want folder specific layouts i.e. (Home, Account, Product etc), you can put _ViewStart.cshtml in that folder & point out whichever layout tobe used in that file & it will override the root level layout.

Find ScottGu's blogs for more details on layouts & sections here & here

like image 44
Pravin Pawar Avatar answered Nov 20 '22 06:11

Pravin Pawar