网页通常与对象有关。
您已经看到了一些页面对象方法的使用:
@RenderPage("header.cshtml")
@RenderBody()
在上一章中,您看到使用了两个页面对象属性(IsPost 和 Request):
If (IsPost) {
if (Request["Choice"] != null) {
Method | Description |
---|---|
href | Builds a URL using the specified parameters |
RenderBody() | Renders the portion of a content page that is not within a named section (In layout pages) |
RenderPage(page) | Renders the content of one page within another page |
RenderSection(section) | Renders the content of a named section (In layout pages) |
Write(object) | Writes the object as an HTML-encoded string |
WriteLiteral | Writes an object without HTML-encoding it first. |
Property | Description |
---|---|
IsPost | Returns true if the HTTP data transfer method used by the client is a POST request |
Layout | Gets or sets the path of a layout page |
Page | Provides property-like access to data shared between pages and layout pages |
Request | Gets the HttpRequest object for the current HTTP request |
Server | Gets the HttpServerUtility object that provides web-page processing methods |
页面对象的 Page 属性提供对页面和布局页面之间共享的数据的类似属性的访问。
您可以使用(添加)您自己的属性到 Page 属性:
页面属性非常有帮助。例如,它可以在内容文件中设置页面标题,并在布局文件中使用它:
@{
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}
<h1>Welcome to 91xjr</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>
<!DOCTYPE html>
<html>
<head>
<title>
@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!