Transferring an object from a controller to another 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 });
    }

you can pass object b to other actions on another controller, in this case, SomeAction on SomeController. thank you for your help:)

+3
source share
2 answers

In your first detail action,

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

In the action you want to get, SomeAction

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

Edit: You do not need parameters in RedirectToAction in this way.

+6
source
0
source

Source: https://habr.com/ru/post/1731306/


All Articles