In a new ASP.NET site there is a ContentPlaceHolder for the title:
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>
In the page:
<asp:Content ID="aboutTitle" ContentPlaceHolderID="TitleContent" runat="server">
About Us
</asp:Content>
Why is this? Why can't the title property/attribute be used on the page directive?
<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
Both methods have the same result. For me the ContentPlaceHolder approach seems hackish.
If you needed a dynamic title you can do it like this in the aspx page:
<%= this.Title = "About Me" %>
See this post.
If you used Title attribute of @Page directive instead you would have to set an application-wide title in each view duplicating code and violating single responsibility principle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With