开发者

Passing Object from controller to other controller

Here is the problem,

i have one controller:

[AcceptVerbs(开发者_JAVA技巧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 :)


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜