Daniel T.
Daniel T.

Reputation: 38400

ASP.NET MVC ContentPlaceHolder overriding hard-coded content

This is what I have in the aspx page:

<head runat="server">
    <title>Website - <asp:ContentPlaceHolder ID="HeadContent" runat="server" /></title>
</head>

This is what's in the view:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    Homepage
</asp:Content>

For some reason, this HTML is generated:

<title>Homepage</title>

The 'Website - ' part is getting removed. Anybody know how I can fix this?

Upvotes: 3

Views: 2512

Answers (2)

laurie
laurie

Reputation: 106

Phil Haack has an explanation of this issue (and a work-around) at http://haacked.com/archive/2009/04/03/tipjar-title-tags-and-master-pages.aspx . The work-around is that you use an asp:LiteralControl for the static part of your page title.

Upvotes: 4

Nick
Nick

Reputation: 5908

could you do something like this?

<head runat="server">
    <asp:ContentPlaceHolder ID="HeadContent" runat="server"><title>Website</title></asp:ContentPlaceHolder >
</head>

and then override the whole title string in your view?

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>Homepage</title>
</asp:Content>

Upvotes: 0

Related Questions