【发布时间】:2017-07-05 11:40:28
【问题描述】:
我在我的客户端 js 脚本中使用这样的 fetch 发布数据
fetch('/myarea/mycontroller/myaction', {
method: 'post',
body: JSON.stringify({ name: namevalue, address: addressvalue })
})
.then(function (response) {
if (response.status !== 200) {
console.log('fetch returned not ok' + response.status);
}
response.json().then(function (data) {
console.log('fetch returned ok');
console.log(data);
});
})
.catch(function (err) {
console.log(`error: ${err}`);
});
}, false);
然后在我的控制器上
[HttpPost]
public async Task<IActionResult> MyAction(string name, string address)
{
// Error, name and address is null here, shouldn't be!
// more code here ...
}
我的控制器动作被正确调用,我可以在其中调试,但没有数据被传递。这里有什么问题?谢谢
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc