صفحات ويب 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>