传递一个模型分成RedirectToAction() [英] Passing a model into RedirectToAction()

查看:313
本文介绍了传递一个模型分成RedirectToAction()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇如何工作的。在MVC中,你可以调用视图(),并通过模型作为一个参数,但RedirectToAction(至少是它的化身之一)有一个'routeValues​​'对象,这似乎是最接近的匹配。

I'm curious how this works. In MVC you can call View() and pass a model as a parameter, but RedirectToAction (one of its incarnations at least) takes a 'routeValues' object, which appears to be the closest match.

如果您的模型在此参数传递将在该机型在随后的操作方法可用?还是有参与警告可能prevent准确的翻译在某些情况下?

If your model is passed in this parameter will that model type be available in the subsequent action method? Or are there caveats involved that might prevent accurate translation in some circumstances?

推荐答案

如果你需要传递一些,有什么复杂的对象到重定向后的动作,你可能想使用一个会话或TempData的:

If you need to pass in some-what complex objects to an action after a redirect, you probably want to use either a Session or TempData:

什么是ASP.NET MVC的TempData

ASP.NET MVC的TempData词典是用来之间的数据共享
  控制器动作。 TempData的价值仍然存在,直到它被读取或
  直到当前用户的会话超时

ASP.NET MVC TempData dictionary is used to share data between controller actions. The value of TempData persists until it is read or until the current user’s session times out

在默认情况下使用TempData的会话坚持的信息,但是,与很多MVC的,这是一个扩展点,在那里你可以在一个的基于Cookie的提供商如果preFER。

By default TempData uses a Session to persist the information, however, as with much of MVC, this is an extensibility point, where you can plug in a Cookie-based provider if you prefer.

这篇关于传递一个模型分成RedirectToAction()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆