Páginas Web ASP.NET - Objetos
Las páginas web suelen tratarse de objetos.
El objeto de la página
Ya ha visto algunos métodos de objetos de página en uso:
@RenderPage("header.cshtml")
@RenderBody()
En el capítulo anterior, vio que se usaban dos propiedades de objetos de página (IsPost y Request):
If (IsPost) {
if (Request["Choice"] != null) {
Algunos métodos de objetos de página
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. |
Algunas propiedades de objetos de página
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 |
La propiedad de página (del objeto de página)
La propiedad de página del objeto de página proporciona acceso similar a una propiedad a los datos compartidos entre páginas y páginas de diseño.
Puede usar (agregar) sus propias propiedades a la propiedad Página:
- Título de la página
- Página.Versión
- Página.cualquier cosa que te guste
La propiedad de las páginas es muy útil. Por ejemplo, permite establecer el título de la página en los archivos de contenido y usarlo en el archivo de diseño:
Inicio.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>
Diseño.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
</head>
<body>
@RenderBody()
</body>
</html>