差异的ViewData和TempData的关系? [英] Difference Between ViewData and TempData?
问题描述
我知道ViewData的是什么,用它所有的时间,但在ASP.NET preVIEW 5,他们引入了一种叫做TempData的新的东西。
I know what ViewData is and use it all the time, but in ASP.NET Preview 5 they introduced something new called TempData.
我通常强类型我的ViewData,而不是使用对象方法的字典。
I normally strongly type my ViewData, instead of using the dictionary of objects approach.
所以,当我应该使用TempData的,而不是ViewData的?
So, when should I use TempData instead of ViewData?
是否对此有任何的最佳做法?
Are there any best practices for this?
推荐答案
在一个句子:的TempData code>像ViewData的一个区别:它们只包含两个连续请求之间的数据之后,它们被破坏。您可以使用
的TempData code>传递错误信息或类似的东西。
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.
虽然已经过时,这篇文章具有良好在的TempData code>生命周期的描述。
Although outdated, this article has good description of the TempData
lifecycle.
由于本Scheirman说<一href=\"http://web.archive.org/web/20110808062247/http://flux88.com/2008/01/testing-tempdata-in-asp-net-mvc/\"相对=nofollow>这里:
As Ben Scheirman said here:
TempData的是,可用于一个单一的请求的会话支持临时存储的字典。这是伟大的传递控制器之间的消息。
TempData is a session-backed temporary storage dictionary that is available for one single request. It’s great to pass messages between controllers.
这篇关于差异的ViewData和TempData的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!