since I'm new in jquery, can you tell me how to redirect a page to another action method ? I develop a MVC web application. I use jquery post method to do some validation, and when it return true, it will be redirect page to another one. My problem is..when when I redirect page using window.location, it's works well in IE (IE 9). but didn't work on firefox & chrome. So, I try to using jquery post method to redirect page from action method in my controller. I call redirect post method in a jquery post call back. it is my code :
$.post(posturl, formData, function (result) {
if (result == 'True') {
$.post("/Controller/RedirectMethod", {_Action: 'Index', _Controller: 'Home'}, null);
}
else
alert('failed');
}
);
and this is my RedirectMethod :
[HttpPost]
public ActionResult RedirectMethod(string _Acti开发者_C百科on, string _Controller)
{
return RedirectToAction(_Action, _Controller);
}
so how I should create a nested post in another post callback ? or there is another way to redirect page ?
thanks,
You won't be able to do a RedirectToAction inside an Ajax request.
If you need the web page to change to a different location inside the Ajax response, use window.location as Ben suggested.
One thing to bear in mind is that you'll need to remove the 'HttpPost' action filter.
精彩评论