I have an ASP.NET MVC Form, but the data from it needs to be posted via jQuery (not ajax). It cannot be submitted using the normal model, because the Controller Action requires a JSON string, and the only way to get that string is to use jQuery's $.post method to turn the data into JSON, and then post it to the Controller.
This works fine. However the end result is that after posting, the form is supposed to Redirect to a different page (Like a Success Page). This does not occur, it just stays on the same page.
If I use return false; in my jQuery code, it will stop the form from trying to post again, but this doesn't solve my problem. I really don't want to set the URL manually, either, since I want to keep as much out of javascript as humanly possible.
Controller
[HttpPost]
public ActionResult Receive([FromJson] jsonObject item)
{
if (ModelState.IsValid)
{
// logic
}
return RedirectToAction( ... );
}
JavaScript
$('.submit').click(function(e) {
var json = JSON.stringify(data);
$.post( location.href, { item: data});
});
This submits the code right. and the return statement even gets hit if I step through it in the debugger, but it never does the redirect. What can I do?