0

I have the following controller action:

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
public ActionResult Index()
{
    var postedData = Request.Form["param1"];
    return View("/someView.cshtml");
}

When I post data to it in the following way:

$('#btn1').click(function () {
    $.ajax({
        type: 'POST',
        url: someUrl,
        data: { param1: 'some data' },
        async: false //tried without this line with no affect
    });
});

It doesn't redirect and it requires a registration to the success callback and invocation of a window.location.href to redirect to the view.
If I'll create a form and submit it with the data to the same controller action a redirection will occur in the same request.

Why does a jquery post doesn't trigger a redirection whereas a form submit to the same action does? Do I have to use a form in order to POST and redirect over the same request?

Yoav
  • 3,326
  • 3
  • 32
  • 73
  • http://stackoverflow.com/questions/473038/post-versus-ajax-call – Ivaylo Stoev Jan 22 '17 at 12:23
  • http://stackoverflow.com/questions/1538523/how-to-get-an-asp-net-mvc-ajax-response-to-redirect-to-new-page-instead-of-inser – Si Bxxx Jan 22 '17 at 16:10
  • Ajax response is handled within the Ajax request and no redirects are happening, unless you have a location change script in the response from Ajax call – Saravanan Jan 22 '17 at 17:07
  • The whole point of ajax is to stay on the same page (ajax calls never redirect). If you want to redirect, make a normal submit. –  Jan 22 '17 at 21:48

0 Answers0