Asp. Net MVC5 entry-level Learning Series ③

Source: Internet
Author: User

Add a View)

Next, in the first entry series, we will add a simple Controller (Controller). Here we will simply add a View to demonstrate how to execute the Action in our Controller) result After Action/method.

Modify our HelloWorldController to the Code created by default, as shown below:

Then we add an Index view in the Views/HelloWorld folder. When adding the view, we choose to use the template. The specific operations are as follows:

Then select _ Layout. cshtml as our template and click "OK". The project structure is as follows.

The simple code for writing down the page is as follows:

Then we can run the Page Inspector in VS to see the effect. The operation is as follows:

Running effect:

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

Here, ViewBag is used to obtain the data and then return it to the view layer. The view layer can use ViewBag to read the stored data.

Add a view welcome. cshtml using the MVC template. The Code is as follows:

Then we can run it in the Page Inspector provided by VS to see the effect:

Let's try to insert a value to the simulated HTTP to see if it can achieve our prediction. The operations are as follows and the results are as follows:

In this simple demonstration, ViewBig is used to transmit data to the View layer, and then the View layer obtains data for display through the ViewBig object. In fact, everyone knows that the actual application or development is in progress, data transmission and presentation layer reading data often uses not ViewBig but Model, that is, M in MVC. next we will continue to analyze how to use a View model to redirect the data executed in the Controller to the View layer. Just share so many views!

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.