【发布时间】:2021-01-15 10:00:30
【问题描述】:
这是我的控制器被调用,但值总是以 null 结束:
public void Post([FromBody]string value) {
}
它是这样称呼的:
function () {
var data = {
'sku': $('#radioProduct').val(),
'qty': $('#productQty').val()
}
return fetch('/api/Default', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(data)
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.orderID; // Use the same key name for order ID on the client and server
});
}
});
我在这里做错了吗? API 确实被调用,但主体为空。
【问题讨论】:
-
您的代码看起来不错。查看浏览器开发工具的网络面板,确定实际发送的内容,以便区分客户端和服务器端问题。
标签: javascript api asp.net-web-api