The Page property of the Page Object, provides property-like access to data shared between pages and layout pages.
You can use (add) your own properties to the Page property:
- Page.Title
- Page.Version
- Page.anythingyoulike
The pages property is very helpful. For instance, it makes it possible to set the page title in content files, and use it in the layout file:
Home.cshtml
@{
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}
<h1>Welcome to mytat</h1>
<h2>Web Site Main Ingredients</h2>
<p>A Home Page (Default.cshtml)</p>
<p>A Layout File (Layout.cshtml)</p>
<p>A Style Sheet (Site.css)</p>
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}
<h1>Welcome to mytat</h1>
<h2>Web Site Main Ingredients</h2>
<p>A Home Page (Default.cshtml)</p>
<p>A Layout File (Layout.cshtml)</p>
<p>A Style Sheet (Site.css)</p>
Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
Practice Excercise Practice now