MVC Template Page

Source: Internet
Author: User

I have learned that the web should know the master page of this thing, here, the MVC template page and the Web Template page is the same effect and purpose.

First: Create a project, controller, generate the index view, when generating the view we select the Razor view engine, and then tick the "Use Layout or master page" option, which defaults to the layout of the _layout.cshtml page referenced. The page has been configured in the _viewstart.cshtml file, and all Razor engine pages will execute this viewstart page before execution.

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

The layout keyword is the code that points to the default page layout. This view is much cleaner than the ASPX view.

Custom Layout page:

<! DOCTYPE html>
<meta charset= "Utf-8"/>
<meta name= "viewport" content= "Width=device-width"/>
<title> @ViewBag .title</title>
@Styles. Render ("~/content/css")
@Scripts. Render ("~/bundles/modernizr")
<body>
<p>this is up</p>
@RenderBody ()
<p> this is down</p>
@Scripts. Render ("~/bundles/jquery")
@RenderSection ("Scripts", Required:false)
</body>

What is written in the Child View page is where the layout page @renderbody defined.

@RenderSection Layout page also has the concept of sections (section)

Of course, our display is still going to be written in the view.

---Index:

@{
Viewbag.title = "Index";
Layout = "~/views/shared/_layout.cshtml";
}

<p>this is layoutview</p>

MVC Template Page

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.