Reputation: 49
I have 2 controllers A and B, both of which have their "index.cshtml". I make an ajax call into a method of A which in turn calls RedirectToAction to a method of B. But the "index" view of B doesn't show up even though the ajax call succeeds. Ajax
@.ajax(function()
{
...
url:"A/MethodToRedirect",
...
});
Controller A
{
public IActionResult MethodToRedirect(param)
{
// do something
return RedirectToAction("Index", "B");
}
}
Upvotes: 0
Views: 107
Reputation: 43959
You can't redirect this way using ajax. There are two ways :
return PartialView("Index");
and add to your ajax:
success: function (result) {
$(div).html(result); // div -id of your div outside of partial
}
return Redirect("http://www.myapp.com");
or return javascript
return Content("<script>window.location = 'http://www.myapp.com';</script>");
Upvotes: 1