ASP. NET MVC 4 Advanced Programming Learning Notes: Chapter III view (2)

Source: Internet
Author: User

Page layout

Layout support is provided in ASP., by default the layout file is saved to the _layout.cshtml,view directory in the/view/shared/directory with a _viewstart.cshtml file, the code inside

    @{"~/views/shared/_layout.cshtml";}

Indicates who is the default layout file under this directory. You can add this code to a specific view file to modify the boilerplate template page.

You can create a _viewstart.cshtml file into a subdirectory that sets the default master page for all views in this directory.

In this layout file, the contents of the content page are embedded by @RenderBody () code.

Section (region) is also supported on this page, and the area content defined in the view is embedded in the template page by @RenderSection ("Scripts", Required:false) .

You can specify whether the area in the view must be defined, and the view defines a region by the following code

@section the contents of the zone name {region}

Partial view 

The features of the partial view are available in ASP. NET MVC, which allows you to get the contents of a partial view and embed it in the current page in the following way.

@{html.renderpartial ("view name", parameter );}
@Html. Partial (" view name "
@{html.renderaction ("ActionName", "Controllername", "Passing Parameters");  For example: @{html.renderaction ("Test", "Home", new {S=item}),//s is the parameter name of the action
@Html. Action ("actionname","controllername",  " Pass parameters ")   

Where action means to invoke the code inside the other action, passing the required data through the parameters, and embedding the contents of the detail view into the page via the return Partialview ().

Where partial means to embed the contents of another detail view directly into the page and pass the data required by the detail view through the parameters.

With the method of the start of the render, the contents of the detail view are written to the current view's response stream, which is a little more efficient. However, you must use code block mode @{code} calls.

A method that does not begin with a render, returns a string value that is embedded in the page.

ASP. NET MVC 4 Advanced Programming Learning Notes: Chapter III view (2)

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.