Reputation: 2287
On page Index i have some form. On submit I use this code in HomeController:
[HttpPost]
public ActionResult Index(EventDetails obj)
{
if (ModelState.IsValid)
{
return RedirectToAction("Index2","Home");
}
else
{
return View();
}
}
public ActionResult Index2()
{
return View();
}
So it will redirect me to another page named Index2. How can i get POST data, sent in "Index" page and use it in "Index2" page. And how to show POST data, sent by prev. page in view page?
Upvotes: 0
Views: 66
Reputation: 2840
Since you're making a GET request after the POST, you cannot send the body from the POST along with it. The easiest fix is to use TempData, to temporarily store the data across requests:
[HttpPost]
public ActionResult Index(EventDetails obj)
{
if (ModelState.IsValid)
{
TempData["eventDetails"] = obj;
return RedirectToAction("Index2","Home");
}
else
{
return View();
}
}
public ActionResult Index2()
{
var obj = TempData["eventDetails"] as EventDetails;
return View(obj);
}
Upvotes: 2