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?
Finally, the PersonModel class object is passed to the RedirectToAction method along with the name of the destination Controller and its Action method. The Controller consists of the following Action method. Inside this Action method, the PersonModel class object is received.
The RedirectToAction() Method This method is used to redirect to specified action instead of rendering the HTML. In this case, the browser receives the redirect notification and make a new request for the specified action. This acts just like as Response.
RedirectToAction will return a http 302 response to the browser and then browser will make GET request to specified action. Show activity on this post. Ideally I would use RedirectToRoute for Action Links/Images and RedirectToAction in Controller's Action to redirect to another Controller's Action .
TempData["Model"] = YourModel;
Return RedirectToAction("details");
and in details action, check for TempData["Model"] != null
and grab it from there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With