What is TempData collection used for in asp.net MVC? [duplicate]

China☆狼群 提交于 2019-12-01 01:56:05

问题


What is the actual use of TempData collection in asp.net MVC, I need pros and cons of that collection, and when do I need to use it, which views it is shared upon, or any useful information about it, finally if someone can tell me when to use it rather than ViewData?

Thanks in advance

CLOSED as exact duplicate of Difference Between ViewData and TempData?


回答1:


TempData is used to share data between controller actions. If your controller does a RedirectToAction and the target action needs data (perhaps a particular model instance) to act upon, you can store this data in TempData. Using TempData is similar to storing it in the session, but only for one round-trip. You use TempData when you need to pass data to another controller action rather than a view for rendering.



来源:https://stackoverflow.com/questions/313572/what-is-tempdata-collection-used-for-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!