Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why asp:ContentPlaceHolder on the title replaces the whole title?

Tags:

asp.net-mvc

Using ASP.Net MVC on my Site.Master I have:

<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - MySite</title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>

then on each view I have something like:

<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
    Home
</asp:Content>

and I was expecting, as a result:

 <title>Home - MySite</title>

but instead I've got:

 <title>Home</title>

Any ideas why?

like image 378
pupeno Avatar asked Jan 28 '26 08:01

pupeno


2 Answers

Use this:

<title>
  <asp:ContentPlaceHolder ID="titleContent" runat="server" />
  <%= "- My Site" %>
</title>

The reason is that everything rendered in the head is rendered as a control.

See this question for some further links, and other ways of solving it.

like image 141
boymc Avatar answered Jan 30 '26 20:01

boymc


You may have a Title attribute in the <%@ Page %> directive.

like image 21
Jacob Avatar answered Jan 30 '26 21:01

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!