C# – setting page title when using strongly typed view data in asp.net mvc

asp.net-mvccstrongly-typed-view

How can I set the page title in asp.net mvc using strongly typed views AND a master page.

I added a public property to my master page class, but can't seem to get access to it in my view/action.

Best Answer

Setup a placeholder in the head of your master page:

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>

Then in your view pages add an asp:Content section:

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Model.Title %>
</asp:Content>