且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是asp.net MVC使用TempData集合?

更新时间:2022-11-23 13:19:31

TempData的用于共享控制器动作之间的数据。如果你的控制器做了RedirectToAction和目标的行动需要的数据(可能是一个特定的模型实例)时采取行动,可以存放在TempData的这个数据。使用TempData的类似于会话存储,但只为一个来回。您可以使用TempData的,当您需要将数据传递到另一个控制器行动,而不是渲染视图。

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.