Where and how is the _ViewStart.cshtml layout file linked?

前端 未结 7 502
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 19:58

Here\'s the About.cshtml from the default MVC 3 template:

@{
    ViewBag.Title = \"About Us\";
}

About

Put content here.

相关标签:
7条回答
  • 2020-11-28 20:52

    This may add some addt'l info to this question now (2016 ala MVC4, MVC5).

    The Razor engine finds and runs the code in _ViewStart.cshtml before any other code which is in the same directory or subdirectory where the _ViewStart.cshtml is found.

    Any view can override the Layout property or any of its values.

    Just thought I might add a bit more info to show you why it is _ViewStart.

    If you get ILSpy and examine the code in the RazorViewEngine (System.Web.Mvc.dll ) you will see that the code itself references that name.

    _ViewStart in  System.Web.Mvc.dll

    You can see that the RazorViewEngine looks for a file with that name:

    RazorViewEngine.ViewStartFileName = "_ViewStart";
    
    0 讨论(0)
提交回复
热议问题