ASP MVC5 Introductory Learning series ③

Source: Internet
Author: User

Original: ASP. MVC5 Introductory Learning Series ③

Add a View

Next to the introductory series, the above commentary adds a simple controller, where we simply add a view to show the results of our controller's execution action/method.

We modify our Helloworldcontroller to the code created by default, as follows:

Then we add a view of index in the Views/helloworld folder, we choose to use the template when we add it, the following:

Then select _layout.cshtml as our template Click OK after the project structure as follows.

Simply write down the page code as follows:

Then we run the look in the VS again page inspector, as follows:

Run up effect:

Let's simply modify our welcome () method as follows:

Here the viewbag is used to get the data, and then back to the view layer, the view layer can use ViewBag to read the stored data.

We continue to add a view welcome.cshtml that uses the MVC template, with the following code:

Then we run the look in the VS-Bring page Inspector:

We tried to give it a plug in analog HTTP to see if we could achieve the purpose of our predictions, operation as follows and result:

Here the simple demonstration uses the Viewbig to pass the data to the view layer, then the view layer obtains the data through the Viewbig object to display, actually everybody also knew that the actual application or the development, transmits the data and the presentation layer to read the data to use is not viewbig but the model, That is, the M in MVC. We continue to analyze how to use a view model to turn the data in the controller into the view layer. About view simply share so much!

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.