RedirectToAction not working after successful jquery ajax post? [duplicate]

You cannot redirect from an AJAX post. You could return the URL you want to redirect the browser to however and redirect from Javascript.

Controller

[HttpPost]
public ActionResult GoHome()
{ 
     return Json(Url.Action("Index", "Home"));   
}

Javascript

$.ajax({
    type: "POST",
    url: "http://localhost/UserAccount/GoHome",
    dataType: 'json',
    crossDomain: true,
    success: function (data) {
        window.location.href = data;
    }
});

Leave a Comment