MVC 5 Displays data using ViewData (object)

Source: Internet
Author: User

After the controller coordinates the data, it is presented to the view to display the data. The controller interacts with the view with one that is viewdata.
In this exercise, insus.net will use it as an example.

Some time ago, Insus.net implemented the practice of transmitting data from the controller to the view, such as:
The DataTable data is shown in the MVC application http://www.cnblogs.com/insus/p/3361182.html
MVC uses non-Entity Framework to display data in view http://www.cnblogs.com/insus/p/3364235.html
MVC uses non-Entity Framework to display data in view (ii) http://www.cnblogs.com/insus/p/3364482.html
"MVC shows detailed records without Entity Framework" http://www.cnblogs.com/insus/p/3366608.html
Even in this article, "MVC 5 display, creation, editing, deletion and other functions practice" http://www.cnblogs.com/insus/p/3372916.html also listed.

In order to demonstrate the use of ViewData to transfer data from the controller to the view, first create an object in the model:




After everything is basically ready, the next step is to go to the topic, create the controller, and refer to the steps:



A different window will open:



To modify the controller name:




Controller detail code, which declares an anonymous object directly in the action of the control and assigns a value. This is a slight value from the database. The highlighted code (#23行) is the focus of the whole picture below.




To create a view below, refer to the steps in (1) step, you need to create a directory, the same as the controller name. This is a different place in the previous versions of MVC 5.


After the "Add Scaffold" window appears, select "MVC 5 View" and click the "Add" button.



The "Add View" window appears, in step (6), give the view name of an action, and in step (7), select an empty (without model).



To write the View code:



Operation Result:


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.