Interconnection Power Learning Asp.net mvc3-view and Page Template

Source: Internet
Author: User

In the previous article, Asp.net mvc3-Quick Start should give you a basic understanding of mvc3. Let's take a look at the simple usage of visual diagrams in mvc3.

First, let's modify "My MVC application" in the page title.Program"Text. This text is a public title in all pages. In this application, although this common title is displayed on all pages, it is set in only one place. Open the _ layout. cshtml file in the shared folder under the views folder in Solution Explorer. This file is called a layout page. It is located in the shared public folder and is shared by all other webpages.

The layout template page allows you to specify the layout of the entire web application or all HTML pages of the web site in one place. Pay attention to the "@ renderbody ()" at the bottom of the file ()"CodeLine. @ Renderbody () is a placeholder that represents all the view pages of the actual application you have created. It is specified here. Change "My MVC application" in the layout template file to "my mvcbooks application ". The Code is as follows.

Run the application. Note that the title on the webpage is changed to "my mvcbooks application ". Click the "about" link. You can see that the title on the "about" page is changed to "my mvcbooks application ". It can be seen that once a place in the layout page is modified, the modification will be applied to all pages.

Now, let's Modify the title of the index view page.

Open the index. cshtml file in the helloworld folder under the views folder. Here we can modify two places: first, modify the title in the browser, and then modify the title text in the <H2> label. The modified code is shown in code list 3-3.

Code List 3-3 The modified index. cshtml view Template File

The title attribute of the viewbag object represents the title text in the browser when the page is displayed. Let's look back at the layout template file. This value is used in the <title> label in the

Run the application and enter "http: // localhost: xxxx/helloworld" in the address bar. Note the web page title in the browser, the title text on the page is changed to the modified title text (if it does not change, Your webpage may be cached, you can press Ctrl + F5 to cancel the cache when you refresh the page ).

Note that the content in the placeholder in the _ layout. cshtml file is replaced with the content in the index. cshtml view template. Therefore, the browser displays a single HTML file. The running result in the browser is 3-7.

Figure alt: The index view template file after the title is modified

Here, our data ("this is my first view template" text) is directly written in the file, that is, we use the "v" (view) of the MVC application) and "C" (Controller ). Next, we will explain how to create a database and obtain model data from the database.

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.