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!