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?