The default master-page template added to new
ASP.NET MVC projects now has an <asp:contentplaceholder/> element within
its <head> section. This makes it much easier for view templates to
control the <title> element of the HTML page rendered back – and not
require the Controller to explicitly pass a “title” parameter to configure it
(which was the default with previous ASP.NET MVC builds and we thought
questionable from a responsibilities perspective).
For example, to customize the <title> of
our Edit view to include the current product name we can now add the below code
to our Edit.aspx template to drive the title directly off of the model object
being passed the view:
Figure 25
The above code will then cause the browser to render the
title using the Product name at runtime:
Figure 26
In addition to setting the <title>
element, you can also use the above approach to dynamically add other
<head> elements at runtime. Another common scenario this is useful
with is configuring model/view specific <meta/> elements for search
engine optimization.