I have a simple controller API which combine with mvc view, which i want to hit the route controller from ajax post
The problem is the route address never match when i post from ajax
maybe somebody can help me
thank u
[HttpPost]
//[ValidateAntiForgeryToken]
[Route("pin")]
public IActionResult Index(string pin, string returnUrl = "")
{
return View();
}
function postpin() {
var pin = $('input').map(function () {
return this.value;
}).get().join('');
var res = validate();
if (res == false) {
return false;
}
//alert(pin);
var requestreturnUrl = $("#requestreturnUrl").val();
$.ajax({
cache: false,
type: 'POST',
// beforeSend: function (xhr) {
// xhr.setRequestHeader("X-CSRF-TOKEN",
// $('input:hidden[name="__RequestVerificationToken"]').val());
// },
url: '/PIN?pin=' + pin + '',
data: { pin: pin, returnUrl: requestreturnUrl },
contentType: 'application/json; charset=utf-8',
datatype: 'json',
success: function (response) {
alert("success");
},
error: function (err) {
alert(err);
}
});
}