【发布时间】:2018-07-23 18:25:36
【问题描述】:
在这里使用 angularjs 和 c# webapi。
我正在从传入我的 json 数组的 angularjs 调用我的 webapi。
Angularjs 代码:
factory.delete = function (json) {
var url = 'myUrl';
return $http.post(url, json).then(function (res) {
return res;
}, function (err) {
throw err;
});
}
C# API:
[HttpPost("data/delete")]
public async Task<IActionResult> DeleteData([FromBody] List<UserEntity>
jsonData)
{
//loop through json and do delete here
}
是正确的删除方式,我这里用的是post而不是httpdelete。上面的方法有效
我尝试使用 http delete 为:
factory.delete = function (ids) {
var url = 'myUrl';
return $http.delete(url, ids).then(function (res) {
return res;
}, function (err) {
throw err;
});
}
[HttpDelete("data/{ids}/delete")]
public async Task<IActionResult> DeleteData(string ids)
{
//here ids is comma separated ids which I want to loop through and delete one by one
}
这个问题是我在 api 中的 ids 参数始终为空。不知道这里发生了什么。
请输入任何内容。
【问题讨论】:
-
请提供示例 json 有效负载以及 UserEntity 类的内容。由于这两者是相关的,因此此处的不匹配将导致您的参数值为 null。
标签: javascript c# angularjs