Nikola Sivkov
Nikola Sivkov

Reputation: 2852

How to properly pass variable between action methods?

I have one ListController that lists items, and a ManageController that handles different actions for the selected item from ListController.

So, how do i pass the variable to the ManageController (and its sub actions) so that it is there even when a user opens the the same URL in a different browser.

This excludes Sessions and Cookies directly.

Any ideas ?

Upvotes: 1

Views: 415

Answers (1)

Patrick D'Souza
Patrick D'Souza

Reputation: 3573

You could try saving the data to be shared in TempData which is like saving data in the Session but the data will be deleted automatically in the end of the request where it was read.

[HttpPost]
public ActionResult FirstAction()
{
    ...
    TempData["sharedData"] = data;
    return RedirectToAction("SecondAction");
}

public ActionResult SecondAction()
{
    var data= TempData["sharedData"];

    return View(data);
} 

Upvotes: 2

Related Questions