zulkifli
zulkifli

Reputation: 47

Passing Object from controller to other controller

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 :)

Upvotes: 3

Views: 1971

Answers (2)

Steve Horn
Steve Horn

Reputation: 8959

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/

Upvotes: 0

elwyn
elwyn

Reputation: 10521

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.

Upvotes: 7

Related Questions