ASP.NET Web Pages Object
Halaman Web yang sering dikaitkan dengan objek.
halaman Objek
Anda sudah melihat beberapa metode Halaman objek digunakan:
@RenderPage("header.cshtml")
@RenderBody()
@RenderBody()
Pada bab sebelumnya, Anda telah melihat dua sifat Halaman objek (isPost dan Permintaan):
If (isPost) {
if (Request["Choice"] != null {
if (Request["Choice"] != null {
Beberapa metode Halaman objek
方法 | 描述 |
---|---|
href | 使用指定的值创建 URL。 |
RenderBody() | 呈现不在布局页命名区域的内容页的一部分。 |
RenderPage( page ) | 在另一个页面中呈现某一个页面的内容。 |
RenderSection( section ) | 呈现布局页命名区域的内容。 |
Write( object ) | 将对象作为 HTML 编码字符串写入。 |
WriteLiteral | 写入对象时优先不使用 HTML 编码。 |
Beberapa properti obyek Halaman
属性 | 描述 |
---|---|
isPost | 如果客户端使用的 HTTP 数据传输方法是 POST 请求,则返回 true。 |
Layout | 获取或者设置布局页面的路径。 |
Page | 提供了对页面和布局页之间共享的数据的类似属性访问。 |
Request | 为当前的 HTTP 请求获取 HttpRequest 对象。 |
Server | 获取 HttpServerUtility 对象,该对象提供了网页处理方法。 |
Halaman properti objek halaman
Halaman Halaman atribut objek, yang menyediakan akses ke sifat yang mirip dibagi antara halaman dan data tata letak halaman.
Anda dapat menggunakan Page Properties (tambahkan) atribut Anda sendiri:
- Page.Title
- Page.Version
- Page.anythingyoulike
sifat halaman sangat berguna. Misalnya, mengatur judul halaman dalam file konten dan menggunakan tata letak file:
Home.cshtml
@{
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}
<h1>Welcome to W3CSchool.cc</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 W3CSchool.cc</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