视图如何知道要使用哪种布局?默认在哪里?

时间:2022-08-23 08:11:08

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

在默认的mvc应用程序中。有布局和内容页面,你知道(_Layout,Home,Contact等)

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?

在内容页面中,此代码丢失。但他们的作品。没有布局参考,它如何做到这一点?

2 个解决方案

#1


9  

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.

因为_ViewStart.cshtml包含对默认布局的引用,当在视图中未声明特定布局时将使用该布局。

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

如果要更改单个视图的布局,可以包含Layout =“...”;对那个观点。

#2


5  

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.

如果您想要特定于文件夹的布局,例如(主页,帐户,产品等),您可以将_ViewStart.cshtml放在该文件夹中并指出要在该文件中使用的任何布局,它将覆盖根级别布局。

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

查找ScottGu的博客,了解有关布局和部分的更多详细信息

#1


9  

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.

因为_ViewStart.cshtml包含对默认布局的引用,当在视图中未声明特定布局时将使用该布局。

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

如果要更改单个视图的布局,可以包含Layout =“...”;对那个观点。

#2


5  

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.

如果您想要特定于文件夹的布局,例如(主页,帐户,产品等),您可以将_ViewStart.cshtml放在该文件夹中并指出要在该文件中使用的任何布局,它将覆盖根级别布局。

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

查找ScottGu的博客,了解有关布局和部分的更多详细信息