从asp.net mvc 3开始Razor在返回View()
的时候先执行"Views"根目录下的_ViewStart.cshtml,再执行对应的view文件
这就是为什么默认的模板套用能在这里找到
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Sample.Site; | |
@{ | |
Layout = "/Views/Shared/_Layout.cshtml"; | |
} |
如果对应的controller目录下也存在"_ViewStart.cshtml"也存在话,那么一直顺序依次为:
- Views/_ViewStart.cshtml
- Views/[ControllerName]/_ViewStart.cshtml
- Views/[ControllerName]/[ViewName].cshtml
如果打算对某些的controller套用不同的模板,只需要将军的在对应的view目录下添加_ViewStart.cshtml并覆盖Layout
就行。
Comments