Difference between ViewData and TempData

Difference Between ViewData and TempData?

In one sentence: TempData are like ViewData with one difference: They only contain data between two successive requests, after that they are destroyed. You can use tempdata to pass error messages or something similar.

Although outdated, this article has good description of TempData lifecycle: http://www.squaredroot.com/post/2007/12/MVC-ViewData-vs-TempData.aspx

As Ben Scheirman said here: http://flux88.com/testingtempdatainaspnetmvc.aspx, "TempData is a session-backed temporary storage dictionary that is available for one single request. It’s great to pass messages between controllers."

原文地址:https://www.cnblogs.com/wucg/p/1916556.html