asp.net mvc - Why is a full path to layout required in viewstart file when locations are specified in the view engine? -


I am playing with a razor view engine and there is something that I do not get enough.

The _ViewStart file specifies a layout with the full file path like this:

  @ {layout = "~ / visible / shared / _MasterLayout.cshtml"; }  

As I understand it, full path and extension should be included. You can not just do this:

  @ {layout = "_MasterLayout"; }  

Although visual engine specifies the locations to search for master scenes:

  MasterLocationFormats = new string [] {"~ / views / {1} /{0}.cshtml "," ~ / visible / share / {0} .cshtml "};  

How is the full path of the master layout file needed in the _ViewStart file?

And if the full path is specified, then what is the MasterLocationFormats [] ?

What is the point of specifying potential locations in updates

OK, I still have not found a satisfactory answer on this.

Using this will appear that MasterLocationFormats either ingest or overstread when the layout specifies the layout in the file

I use MasterLayout Can completely remove the .cshtml location from masterlocation formats and it did not make any difference in web page display.

My personal question was due to its use, allowing you to specify the razor view to use as a template to send HTML emails. It uses MasterLocationFormats

So I'm still a bit confused, but hopefully this will be used by anyone some . other than this,.

A new RazorView is created in the CreateView implementation of RazorViewEngine.

And when RazorView overrides the RenderView method of BuildManagerCompiledView, which creates the actual call to render the IView's render method.

And at the end of this execution, that line is called.

  webViewPage. ExecutePageHierarchy (New WebPageContext (reference: viewContext.HttpContext, page: blank, model: tap), author, start page);  

And it leads us to the ExecutePageHierarchy method of WebViewPage, which is in System.Web.Mvc.dll.

  public override zero ExecutePageHierarchy () {TextWriter Author = This.ViewContext.Writer; This.ViewContext.Writer = this.Output; Base.ExecutePageHierarchy (); If (String.IsNullOrEmpty (this.OverridenLayoutPath)) it. Layout = this.OverridenLayoutPath; This.ViewContext.Writer = Authors; }  

As you can see above the layout path is overridden.

For more information, you can view RazorView and WebViewPage classes.


Comments