Here is my code in my content page and master page respectively:
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<%=Model.Title %>
</asp:Content>
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - WebsiteName</title>
this works for me except sometimes content Pages don’t have titles. So the page title ends up being “-Website” instead of “Website”.
Should I just replace the above by this or is there a better way?
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
- <%=Model.Title %> //downside: remember to append "dash" inside every single view.
</asp:Content>
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /> WebsiteName</title>
A smarter content placeholder
For what I know it would probably be the best way to write a custom web control that inherits from
System.Web.UI.WebControls.ContentPlaceHolderclass. To make it as universal as possible (so you can publish it on the web) you could add three additional properties:This will make it quite usable. You would be able to put content inside parentheses, add dashes, semicolons etc. The boolean property defines whether prefix and suffix should be added even if there’s no content.
In your case this control on master page pages would look like:
but you could easily make things like:
or similar.