When ASP.NET MVC executes a page containing Razor it will first run the body eg the RenderBody
method then it runs the code for the layout and weaves it together.
This is documented in this blog post:
System.Web.Mvc.RazorView.RenderView() System.Web.WebPages.WebPageBase.ExecutePageHierarchy() //non virtual version System.Web.WebPages.WebPageBase.PushContext()
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() //virtual version this.Execute() //Generated code from our View
System.Web.WebPages.WebPageBase.PopContext
RenderSurrounding(virtualPath, body); //Render Layout, which is similar to View's rendering process, essentially you can have nested Layout VerifyRenderdBodyOrSetions();
I want to add code to my views and layout that traces the actual logical position in the page.
Is there a way I can hook up a method to run just before RenderSurrounding and just after RenderBody
finishes executing?