I'm trying post data from View to controller and then return back to view to get feedback from controller. This is my script in view.
<script type="text/javascript">
$(document).ready(function () {
$("Submit").click(function (e) {
e.preventDefault();
var token = $('input[name=__RequestVerificationToken]').val();
console.log(token);
var dataToPost = $(this).serialize();
$.ajax({
url: "Process/Payment"
, method: "POST"
, data: {
__RequestVerificationToken: token
, page: dataToPost
}
, done: function (data) {
window.location.replace (data.newUrl);
alert(data);
}
, error: function () {
alert("Ajax call failed");
}
})
})
})
and this is my controller. All data that wrap in 'Payment' model is in good shape, pass well from view to controller. And, I want to return back to view (url: "Process/Payment")
[HttpPost]
public ActionResult Allowance (Allowance allowance) {
return Json(new {
newUrl = Url.Action("Payment", "Process")
}
);
but when the page return to localhost, I just get this page.
How should I do to return the page that look like before I hit submit button as POST ?
why "window.location.replace ()" can't redirect page to the original page ?
Thx's