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!