简体   繁体   English

在ASP.Net MVC中使用布局页面时,是否在每次调用新页面时加载布局?

[英]When using a layout page in ASP.Net MVC is the layout loading every time a new page is called?

I'm just curious to know, because I'm still learning layout pages, if when I use a layout page (ex. SiteLayout.cshtml) and have two pages getting rendered with it (Index.cshtml, Results.cshtml) in the @RenderBody() section, does the layout wrapper part get loaded each time I go between Index.cshtml and Results.cshtml? 我只是想知道,因为如果我在使用布局页面(例如SiteLayout.cshtml)并在其中使用两个页面(Index.cshtml,Results.cshtml)渲染时,我仍在学习布局页面。 @RenderBody()部分,每次我在Index.cshtml和Results.cshtml之间移动时,是否会加载布局包装器部分? Or does the _layout.cshtml page load the @Renderbody() section asynchronously? 还是_layout.cshtml页面异步加载@Renderbody()部分?

Just to throw in some example pics 仅举一些例子照片

在此处输入图片说明

在此处输入图片说明

Unless you've setup donut caching ( http://weblogs.asp.net/scottgu/tip-trick-implement-donut-caching-with-the-asp-net-2-0-output-cache-substitution-feature ), the SiteLayout.cshtml will get executed separately for every page. 除非您设置了甜甜圈缓存( http://weblogs.asp.net/scottgu/tip-trick-implement-donut-caching-with-the-asp-net-2-0-output-cache-substitution-feature ) ,将分别为每个页面执行SiteLayout.cshtml

If your SiteLayout has some long/expensive operation and you don't want it loading every time, you can use the aforementioned donut caching to have it execute once per user per X amount of time. 如果您SiteLayout有一些长/昂贵的操作,你希望它每加载时间,你可以使用上述甜甜圈缓存有它每一次X量每个用户执行一次。

If you want the SiteLayout to start sending data to the browser before the body is done executing/rendering (ie asynchronously for overall speed purposes), you can use a nuget package called CourtesyFlush ( http://www.hanselman.com/blog/NuGetPackageOfTheWeekCourtesyFlushToFlushBuffersEarlierAndOptimizeTimeToFirstByte.aspx ) 如果您希望SiteLayout在主体执行/渲染之前(即,为了整体速度而异步)开始向浏览器发送数据,则可以使用一个名为CourtesyFlush的nuget包( http://www.hanselman.com/blog/ NuGetPackageOfTheWeekCourtesyFlushToFlushBuffersEarlierAndOptimizeTimeToFirstByte.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM