【发布时间】:2019-01-29 09:57:45
【问题描述】:
在我的 .Net Core API 中,我返回 ObjectResult
[HttpGet("[Action]")]
public ObjectResult GetBList()
{
List<PendingListBWise> BList = new List<PendingListBWise>();
try
{
BList = GetBWiseList();
return StatusCode(202, BList);
}
catch (Exception ex)
{
return StatusCode(500, new ResultSet() { Message = ex.Message, StatusCode = 500 });
}
finally
{
}
}
现在在我的角度组件中,如果状态码不是 202,我想打印消息。 (更新 1)
GetBList() {
this.ListLoader = true;
var url = this.baseurl + 'api/GeneratePDF/GetList/';
this.http.get<PendingListBWise[]>(url)
.toPromise()
.then(result:HttpResponse<PendingListBWise[]> => {
this.BList = result;
this.ListLoader = false;
})
.catch(error => {
this.ListLoader = false;
console.error(error);
});
}
.then(result:HttpResponse => { } 预期有 0-2 个参数,但得到了 3 个
为了在这里获取响应代码,我必须这样做
.subscribe(result:httpResponse => {
console.log(result);
}, error => {
console.error(error);
});
但是从 PendingListBWise[] 中删除结果的转换,这意味着结果不会被输入到所需的类中,
如何在此处获取数据和状态码?
【问题讨论】:
-
可以使用泛型,所以改成
result: HttpResponse<PendingListBWise[]>,用result.body获取值 -
@user184994 它说预期的 0-2 参数但得到了 3
-
哪一行给出了这个错误?在上面的示例中,该函数仅使用 2 个参数
-
检查更新 1,到达那里后有
,尽管删除它没有帮助
标签: angular asp.net-web-api .net-core