Jquery和控制器代码如下所示
JQuery的:
$.ajax({
url: "/api/ComicApi",
datatype: "text",
data: encoded, //encoded is a MIME64 string
type: "POST",
error: function (request, status, error) {
alert('error');
},
success: function (data) {
}
});
ComicApiController.cs
// POST api/<controller>
[HttpPost] // tried with [HttpPost] and without
public void Post([FromBody]string data)
{
// I hit my breakpoint, but data is ALWAYS null
}
答案 0 :(得分:0)
你能用[HttpPost]
$.ajax({
type: 'POST',
url: "/api/ComicApi",
data: JSON.stringify(encoded),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
error: function (request, status, error) {
alert('error');
},
success: function (data) {
console.log("success");
}
});