Consistent Layout in ASP. NET Razor

Source: Internet
Author: User

Meaningful reference: Http://www.asp.net/web-pages/tutorials/working-with-pages/3-creating-a-consistent-look

How does ASP. NET solve the problem of consistent layout? is solved by introducing the following concepts and providing the appropriate mechanisms:

  • Content Blocks, contents block, is a file containing HTML content, can be "inserted" into other pages, generally not directly accessible, similar to the concept of user control in Web form;
  • Layout pages, which are pages that contain HTML content, can be "inserted" into other pages, where their contents can be shared by "inserted pages", similar to the concept of the master page in Web form;
  • Content page, a general page where you can insert a content Block using Renderpage ("Content Blcok file path"), and use the @layou= "layout page path" to refer to the layout page, The location where the page appears on the layout page, the layout page renderbody (only one renderbody method can be defined in the layout page), is where the method appears;
  • The Renderpage method is used to invoke the Renderpage ("Content block file Path") method on other pages where you want to insert the content block into other pages where the content block is "inserted";
  • The Renderbody method is used to define the location of the content page in layout pages;
  • In addition to defining static content that is shared by other pages, the layout pages page can also be predefined with content that can be defined by the Contents page pages that reference the layout page. This is done by calling Rendersection on the layout page to define the area that is implemented by the content page page, each with a unique name that defines the specific contents of the area by using @section in the content page. Examples are as follows:
    1 in the layout page, use:2 @RenderSection ("header", Required:false)3 or:4 @if (issectiondefined ("header")) {5 @RenderSection ("header")6 }7 8 in the content page:9 @section Header {Ten     <DivID= "header"> One Creating a consistent look A     </Div> -}
    View Code

    In general, this approach may not be used in many scenarios.

  • The Pagedata Property (dictionary type) of the content page that is used to share data between content blocks and layout pages. Refer to the "passing Data to Layout Pages" section in the link above.

Consistent Layout in ASP. NET Razor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.