Can you pass a model with RedirectToAction?

萝らか妹 提交于 2019-12-06 17:40:40

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/1959945/can-you-pass-a-model-with-redirecttoaction

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