ASP. NET MVC TempData usage Experience

Source: Internet
Author: User

    • Description

There are ViewData and TempData in ASP.

ViewData is mainly controller transmit data to view, the lifetime only one action, to cross action to use TempData,

and TempData depending on tempdataprovider, there will be different lifetime, the Tempdataprovider is Sessionstatetempdataprovider,

You are not mistaken, the assumption is to use the session to store TempData,

The session is not stored by the user, and the time period is 20 minutes?

So Sessionstatetempdataprovider have to do some means, controller up, from the session loaded into TempData, and then delete session, So in action you don't see TempData's session, and when you read TempData, you'll remember to use those keys,

When the controller is finished, the tempdata will be stored back into the session, so the tempdata that have not been read will exist until the session disappears .

    • Demonstration
tempdata["RouteName"] = RouteName;  var routeName = tempdata["routeName"]. ToString (); var Oldpagevaluedto = tempdata["oldpagevaluedto" as pagevaluedto; var olddetail = tempdata["olddetail" as Domesticgeneralfeesdetail;

  

ASP. NET MVC TempData usage Experience

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.