Introduction to this section
Methods and properties of the ASP.NET WebPages object.Web Pages are often about objects.
You've already seen some of the Page object methods in use:
@RenderPage("header.cshtml") @RenderBody()
In the previous chapters, you have seen two Page object properties (isPost and Request):
If (isPost) { if (Request["Choice"] != null {
method | describe |
---|---|
href | Creates a URL using the specified value. |
RenderBody() | Renders a portion of the content page that is not in the named region of the layout page. |
RenderPage( page ) | Present the content of one page in another page. |
RenderSection( section ) | Renders the contents of the named area of the layout page. |
Write( object ) | Write the object as an HTML-encoded string. |
WriteLiteral | It is preferred not to use HTML encoding when writing objects. |
property | describe |
---|---|
isPost | Returns true if the HTTP data transfer method used by the client is a POST request. |
Layout | Gets or sets the path of the layout page. |
Page | Provides similar property access to data shared between pages and layout pages. |
Request | Gets the HttpRequest object for the current HTTP request. |
Server | Get the HttpServerUtility object, which provides web page processing methods. |
The Page property of the Page object provides similar property 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
Page properties are very useful. For example, set the page title in the content file and use this in the layout file:
@{Layout="~/Shared/Layout.cshtml";Page.Title="Home Page"} <h1>Welcome to w3cschool.cn</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