In ASP.NET MVC 3 Razor, you can specify the page title with:
@{
ViewBag.Title = "Title";
}
Now, suppose we have a layout page with:
<title>@ViewBag.Title | Website</title>
When ASP goes to render a page, it will need to output some of the layout page HTML, then the view HTML, then the rest of the layout page HTML.
In order to output the first half of the layout page HTML, ASP.NET will need to know the value given to ViewBag.title
in the view. Thus, ASP.NET needs to parse the Razor code in the view. However, ASP.NET can't output the view's HTML code just yet because it is still outputting the layout page's HTML code. So does ASP.NET store the HTML output of the view in a buffer? That seems like a bad practice, but I can't think of any other way to efficiently get the view's title into the layout page output.