views:

59

answers:

2

Here is the problem,

i have one controller:

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Detail(SomeObjectX a)
    {
        SomeObjectY b = new SomeObjectY();

 b.merge(a); //i already have merge method.

        return RedirectToAction("SomeAction", "SomeController", new { c = b });
    }

is it possible to pass object b to other action on different controller, in this case, to SomeAction on SomeController. thanks for your help :)

+4  A: 

In your first action, Detail,

TempData["some-key-here"] = b;

In the action you want to receive the object, SomeAction

SomeObjectY b = (SomeObjectY)TempData["some-key-here"];

Edit: you don't need the parameters in the RedirectToAction this way.

elwyn
your solution works, but my object is in parent child forms, i am afraid it will be dangerous (or heavy maybe?) in the future if i put it in TempData. but i'll use it, because another solution that Steve Horn has given below need MvcContrib library that i am afraid i couldnt use it in my project. (hope in the MVC 2 final release, microsoft will provide another way to solve this problems). thanks for your help.
zulkifli
A: 

Here's a way to pass objects on redirect without using any magic strings: http://jonkruger.com/blog/2009/04/06/aspnet-mvc-pass-parameters-when-redirecting-from-one-action-to-another/

Steve Horn