Layout pages for MVC, view layout pages, and distribution page usage

Source: Internet
Author: User

One, the structure such as

Two, layout page and view layout page

1 "How to use one

_viewstart.cshtml

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

_layout.cshtml

<! DOCTYPE html>"viewport " content="  width=device-width" />    <title> @ViewBag .title</title>        @RenderBody ()    </ Div></body>

Comprehensive:

1 When you use this notation: If the View layout page _viewstart.cshtml does not exist or layout = "~/views/shared/_layout.cshtml", the page fault that points to will cause the layout page of the view (_ layout.cshtml) use failed

2 "But the View layout page _viewstart.cshtml its own style, and so on the same global, and does not expire

2 Using method Two (do not use the View layout page _viewstart.cshtml)

_layoutnew.cshtml

<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title> @ViewBag .title</title>@RenderSection ("Head",false)Layout page _layoutnew.cshtml@RenderSection ("Main",false)    </div></body>

hz.cshtml using templates

@{    "~/views/shared/_layoutnew.cshtml";} @section head{} @section main{            Hz page using _layoutnew.cshtml templates } 

That is, the application of the template is as successful as this, it is important to note that @section head{} @section main{} name needs to be defined as the layout page

Third, the use of partial pages (do not need to create an action, simple to use)

Index.cshtml

@Html. Partial ("_partialview")

You do not need to use the controller (Controllers) and method (action) to directly use the elements of this page

Layout pages for MVC, view layout pages, and distribution page usage

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.