Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TempData becomes null after refresh the page

I used TempData to pass data from an action to another,but when i refresh the page the value of TempData becomes null, how I can solve this probleme? Thanks,

like image 467
Victor Avatar asked Jun 25 '12 17:06

Victor


People also ask

How long does TempData last in MVC?

ASP.net MVC will automatically expire the value of tempdata once consecutive request returned the result (it means, it alive only till the target view is fully loaded).


1 Answers

Use Session instead of TempData. TempData is supposed to be used only for a single redirect. Another possibility is to call the Keep method inside the controller action in which you are consuming the value from TempData. This way if the user refreshes the page by hitting F5 TempData will be persisted for one more request.

like image 150
Darin Dimitrov Avatar answered Oct 20 '22 18:10

Darin Dimitrov