MVC 5 uses TempData object to pass data across views

Source: Internet
Author: User

After a series of exercises showing the data:
MVC 5 uses ViewData (objects) to display data http://www.cnblogs.com/insus/p/3377178.html
MVC 5 uses ViewData (model) to display data http://www.cnblogs.com/insus/p/3377217.html
MVC 5 uses ViewBag (objects) to display data http://www.cnblogs.com/insus/p/3377663.html
MVC 5 strongly Typed views (strongly typed view) http://www.cnblogs.com/insus/p/3377826.html

Is the data passing between the current controller and the view, what if it is necessary to pass from one controller to another? MVC provides an object that is the same as the session, which is called TempData.
The following insus.net also want to list a simple example to show everyone to see.

Originally this exercise was done last night, found that the vs2013 RC trial expired,


Only download the official version, until today to the VS upgrade, download, no need uninstall RC version, directly installed, it will be upgraded on the RC version.
After the upgrade, it was found that there were few changes in MVC 5 when creating model,controll and view.

In the controller write good tempdata:



Then write a link in index.cshtml, in order to let the user click on this link, can link to pagea () this action to.

@Html. ActionLink ("Show to Page A", "PageA")


The TempData data can be used in the pagea.cshtml:



The following live action demo.



You need to know the target view, and the data is passed from one view to another.

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.