Hi All,
I'm trying post data from View to controller and then return back to view. 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");
}
})
})
})
</script>and this is my controller. All data that wrap in 'Payment' model is in good shape. And, I want to return back to view (url: "Process/Payment")
public ActionResult Payment(Payment payment) {
return Json(new {
newUrl = Url.Action("Payment", "Process") //Payment as Action; Process as Controller
}
);
}but when the page return to localhost, I just get this. How should I do to return the page that look like before hit submit button as POST ?
why "window.location.replace ()" can't redirect page to the original page ?
Thx's