Passing data between different controller action methods

Posted by: diva.basemen.0x on 11 September 2022, 3:19 pm EST

    • Post Options:
    • Link

    Posted 11 September 2022, 3:19 pm EST

    I’m using ASP.NET MVC 4. I am trying to pass data from one controller to another controller. I’m not getting this right. I’m not sure if this is possible?

    Here is my source action method where I want to pass the data from:

    public class ServerController : Controller

    {

    [HttpPost]

    public ActionResult ApplicationPoolsUpdate(ServiceViewModel viewModel)

    {

    XDocument updatedResultsDocument = myService.UpdateApplicationPools();

          // Redirect to ApplicationPool controller and pass
          // updatedResultsDocument to be used in UpdateConfirmation action method
     }
    

    }

    I need to pass it to this action method in this controller:

    public class ApplicationPoolController : Controller

    {

    public ActionResult UpdateConfirmation(XDocument xDocument)

    {

    // Will add implementation code

          return View();
     }
    

    }

    I have tried the following in the ApplicationPoolsUpdate action method but it doesn’t work:

    return RedirectToAction(“UpdateConfirmation”, “ApplicationPool”, new { xDocument = updatedResultsDocument });

    return RedirectToAction(“UpdateConfirmation”, new { controller = “ApplicationPool”, xDocument = updatedResultsDocument });

    How would I achieve this?

  • Posted 13 September 2022, 3:18 am EST

    Hi,

    Please refer to the following blog post for reference:

    http://www.binaryintellect.net/articles/8e64d05b-ab2e-45f6-b7f5-b8a90168915e.aspx

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels