ASP.NET वेब पेज - ऑब्जेक्ट
वेब पेज अक्सर वस्तुओं के बारे में होते हैं।
पृष्ठ वस्तु
आप पहले से ही उपयोग में आने वाली कुछ पेज ऑब्जेक्ट विधियों को देख चुके हैं:
@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 |
पेज प्रॉपर्टी (पेज ऑब्जेक्ट की)
पेज ऑब्जेक्ट की पेज प्रॉपर्टी, पेज और लेआउट पेजों के बीच साझा किए गए डेटा तक प्रॉपर्टी जैसी पहुंच प्रदान करती है।
आप पेज प्रॉपर्टी में अपनी खुद की संपत्तियों का उपयोग (जोड़) कर सकते हैं:
- पृष्ठ का शीर्षक
- पेज.संस्करण
- पेज.कुछ भी जो आपको पसंद हो
पेज प्रॉपर्टी बहुत मददगार है। उदाहरण के लिए, सामग्री फ़ाइलों में पृष्ठ शीर्षक सेट करना और लेआउट फ़ाइल में इसका उपयोग करना संभव बनाता है:
होम.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>
Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>