I have a JQuery dialog box on a page that calls something like this:
$.post("/MyController/MyAction", { myKey: key} //...
And this successfully gets here:
[HttpPost]
public ActionResult MyAction(int myKey)
{
//do some stuff
return RedirectToAction("AnotherAction");
}
The problem is that the RedirectToAction has no effect on the webbrowser. I am guessing this is because the JQuery post is kinda on a different ‘tread’ so it doesn’t know where to send the response? How do I get the browser to load the new response?
Yes, the
$.postis doing an ajax post and the Action will not redirect.If you are reditecting anyway, why not just do a form submit, no need for ajax.
Alternatively you could do a
$.getand return a JsonResult to indicate success/failure and redirect using jQuery/javascipt.Update
Something like this:
Where you can set OK or ERR as a result and add any object as the “item” which can be something to use on the View or an error message, url to redirect to etc