In my master page I define the title of the page as follows:
<title开发者_JAVA百科><asp:ContentPlaceHolder ID="TitleContent" runat="server" /><%= "- MyWebSite". %></title>
and then on every view I have something like:
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
Products
</asp:Content>
so that I always end up with the name of the website in the title, like "Products - MyWebSite".
But for one and only one page, the home page, I want only the name of the site, as in "MyWebSite". Ideally I would like that for every view that doesn't define a title, I just show the name of the site. The problems is that with my current code I end up with "- MyWebSite" as title.
Any ideas how to do this without a lot of duplication? Definitely not creating another template.
You could put the - MyWebSite
inside another ContentPlaceHolder
, and make a Content
control for it in the home page (only).
In the master page, you put something like
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
<asp:ContentPlaceHolder ID="TitleSuffixContent" runat="server">
- MyWebSite
</asp:ContentPlaceHolder>
</title>
and while your products page remain
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
Products
</asp:Content>
your home page would be something like:
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
MyWebSite
</asp:Content>
<asp:Content ID="TitleSuffix" ContentPlaceHolderID="TitleSuffixContent" runat="server">
</asp:Content>
or even:
<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
MyWebSite
</asp:Content>
<asp:Content ID="TitleSuffix" ContentPlaceHolderID="TitleSuffixContent" runat="server">
- Your place on the interwebs
</asp:Content>
what you need to do it's simply remove runat="server"
attribute in your head tag
精彩评论