Hello Forum
I have created a test API in Admin/Customercontroller.
MVC
public JsonResult Test(int id)
{
return Json(new
{
Id=id,
Data = "OK",
});
}
When I call it from $.ajax it works fine
I created a similar call with [httpPost]
ViewModel
public class Testdata {
public int Id { get ; set ; }
}
Controller:
[HttpPost]
public JsonResult Test(Testdata test)
{
return Json(new
{
Id = test,
Data = "OK",
});
}
and I call it from Jquery
var url = " http://localhost:15536/Admin/Customer/Test";
var data = { Id: 7 };
$.ajax({
type: "POST",
url: url,
data: data,
contentType: "application/json; charset=utf-8", // this
dataType: "json", // and this
success: function (msg) {
console.info("--->", msg);
},
error: function (errormessage) {
console.info("--->", errormessage);
//do something else
}
});
but I get error 400 badrequest:
POST http://localhost:15536/Admin/Customer/Test 400 (Bad Request)
Any Ideas ?