ASP.NET 웹 페이지 - 개체
웹 페이지는 종종 개체에 관한 것입니다.
페이지 개체
사용 중인 일부 Page Object 메서드를 이미 보았습니다.
@RenderPage("header.cshtml")
@RenderBody()
이전 장에서 두 개의 Page Object 속성(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 개체의 Page 속성은 페이지와 레이아웃 페이지 간에 공유되는 데이터에 대한 속성과 유사한 액세스를 제공합니다.
Page 속성에 고유한 속성을 사용(추가)할 수 있습니다.
- 페이지.제목
- 페이지.버전
- Page.anythingyoulike
페이지 속성은 매우 유용합니다. 예를 들어 콘텐츠 파일에 페이지 제목을 설정하고 레이아웃 파일에서 사용할 수 있습니다.
홈.cshtml
@{
Layout="~/Shared/Layout.cshtml";
Page.Title="Home Page"
}
<h1>Welcome to W3Schools</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>
레이아웃.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>