你可以通过使用RedirectToAction模型? [英] Can you pass a model with RedirectToAction?

查看:132
本文介绍了你可以通过使用RedirectToAction模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC 2候选版本,并想知道是否有任何方式使用RedirectToAction传递模型来操作。

例如,我有一个编辑动作这需要一个ID,并从数据库加载记录,在文本框中显示了当前值,并允许用户编辑和点击提交:

 公众的ActionResult编辑(INT ID)

然后我有这需要一个模型,并更新数据库HttpPost编辑动作:

  [HttpPost]
公众的ActionResult编辑(Administration.Models.ManagementCompanyModel模型)

由于我已经有包含新的数据模型,我不想简单地重新定向到详细的行动,我想以某种方式重定向到细节动作,并通过模型。可能吗?


解决方案

 的TempData [模型] = YourModel;
返回RedirectToAction(详细信息);

和详细的行动,检查的TempData [模型]!= NULL
并从那里抓住它。

I'm using mvc 2 release candidate, and am wondering if there's any way to pass a model to an action using RedirectToAction.

For example, I have an edit action which takes an ID, and loads the record from a database, displays the current values in text boxes and lets the user edit and click submit:

public ActionResult Edit(int ID)

Then I have an edit action for the HttpPost which takes a model and updates the database:

[HttpPost]
public ActionResult Edit(Administration.Models.ManagementCompanyModel model)

Because I already have the model containing the new data, I don't want to simply re-direct to the Details action, I want to somehow redirect to the details action and pass the model. Possible?

解决方案

TempData["Model"] = YourModel;
Return RedirectToAction("details");

and in details action, check for TempData["Model"] != null and grab it from there

这篇关于你可以通过使用RedirectToAction模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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