Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET Web Pages object


May 12, 2021 ASP.NET


Table of contents


ASP.NET Web Pages - Objects

This section describes ASP.NET and properties of Web Pages objects.

Web Pages is often about objects.


Page object

You've seen some page object methods in use:

@RenderPage("header.cshtml")

@RenderBody()

In the previous sections, you saw two Page object properties (isPost and Request):

If (isPost) {

if (Request["Choice"] != null {


Some Page object methods

method describe
href Create a URL using the specified value.
RenderBody() Presenting a part of the content page that is not on the layout page name area.
RenderPage( page ) Render the content of a page in another page.
RenderSection( section ) Render the content of the layout page named area.
Write( object ) Write an object as an HTML encoded string.
WriteLiteral Pre-use HTML encoding is preferred when writing objects.


Some Page object properties

Attributes describe
isPost Returns true if the HTTP data transfer method used by the client is a POST request.
Layout Gets or sets the path to the layout page.
Page A similar property access to the data shared between the page and the layout page is provided.
Request Get httpRequest objects for the current HTTP request.
Server Get httpserverutility objects, which provides a web page processing method.


The Page property of the Page object

The Page property of the Page object, which provides access to similar properties for data shared between the page and the layout page.

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 a content file and use it in a layout file:

Home.cshtml

@{
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