These Are Useful to store Data. Session are destroyed by time that is set by webserver. Viewbag and ViewData work as view as work and destroyed while redirects. How about TempData? Or more useful information.
Asked
Active
Viewed 1.9k times
7
-
hold your session in a database. tempdata only lasts for one page - ie, transfer data from one page to another. viewbag/viewdata are reset on page refresh – mnsr Jul 10 '15 at 05:18
2 Answers
8
The lifetime of TempData
is only available on the current Request
and the subsequent Request
.
You may want to read the article below.
http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications

teo van kot
- 12,350
- 10
- 38
- 70

Bon Macalindong
- 1,310
- 13
- 20
-
1Note to modern readers: TempData's lifetime is different as of .NET Core. See my answer [here](https://stackoverflow.com/a/63818038/5405967) for details. – MarredCheese Sep 09 '20 at 19:13
-
[Even in the old World, TempData lasted longer, than one request](https://stackoverflow.com/a/12815759/2441442), found out today the hard way – Christian Gollhardt Jun 22 '23 at 18:15
5
Here Is Mechanism and more info Data-Passing-Mechanism-in-MVC-Architecture

Moslem7026
- 3,290
- 6
- 40
- 51