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

In the mvc application by default. There are layout and content pages you know (_Layout, Home, Contact, etc.)

And the content pages do not contain a refrence layout, like this:

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

This code is missing on content pages. But they work. How to do this without a macroblock?

+6
source share
2 answers

Because your _ViewStart.cshtml contains a link to the default layout, which will be used if a specific one is not specified in the view.

If you want to change the layout for one view, you must include Layout = "..."; .

+9
source

If you want to use layouts for a folder, that is (Home, Account, Product, etc.), you can put _ViewStart.cshtml in this folder and specify which layout should be used in this file, and it will override the root level layout .

Find ScottGu blogs for more details on layouts and sections here and here.

+5
source

Source: https://habr.com/ru/post/913473/


All Articles