0

After POSTing to a server side method, I want to return the user back to the view from which he came, which was:

.../BrokerDashboard/Profile/Index

Here's the method:

[HttpPost]
public ActionResult Profile(ProfileModel Model)
{
    // do stuff
    return View("Index", Model);
}

There is logic in here that needs to execute after the form is posted:

public ActionResult Index(string contactid)
{
   // do stuff 
}

But after the post, the browser ends up here:

.../BrokerDashboard/Profile/Profile

Which means public ActionResult Index() does not get called again after the post.

daniell89
  • 1,832
  • 16
  • 28
Casey Crookston
  • 13,016
  • 24
  • 107
  • 193

1 Answers1

1

I think what your looking for is RedirectToAction() It causes a redirect and will fire your Index controller method.

RedirectToAction with parameter

https://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.118).aspx

[HttpPost]
public ActionResult Profile(ProfileModel Model)
{
    // do stuff
    return RedirectToAction("Index", Model);
}
Community
  • 1
  • 1
rayepps
  • 2,072
  • 1
  • 12
  • 22