从API返回ObjectResult并在angular中使用状态代码

从API返回ObjectResult并在angular中使用状态代码,angular,asp.net-web-api,.net-core,Angular,Asp.net Web Api,.net Core,在.Net核心API中,我返回ObjectResult [HttpGet("[Action]")] public ObjectResult GetBList() { List<PendingListBWise> BList = new List<PendingListBWise>(); try { BList = GetBWiseList(); return S

在.Net核心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
        {
        }
    }
但从PendingListBWise[]中删除了对结果的强制转换,这意味着结果将不会被输入到所需的类中


如何在此处同时获取数据和状态代码?

首先,从
http.get中删除泛型

然后,将泛型移到
HttpResponse

你应该以这样的方式结束:

  GetBList() {
    this.ListLoader = true;
    var url = this.baseurl + 'api/GeneratePDF/GetList/';
    this.http.get(url)
      .toPromise()
      .then((result: HttpResponse <PendingListBWise[]>) => {
        this.BList = result;
        this.ListLoader = false;
      })
      .catch(error => {
        this.ListLoader = false;
        console.error(error);
      }); 
  }
GetBList(){
this.ListLoader=true;
var url=this.baseurl+'api/GeneratePDF/GetList/';
this.http.get(url)
.toPromise()
.然后((结果:HttpResponse)=>{
this.BList=结果;
this.ListLoader=false;
})
.catch(错误=>{
this.ListLoader=false;
控制台错误(error);
}); 
}

您可以使用泛型,因此将其更改为
result:HttpResponse
并使用
result.body
@user184994获取值。它表示预期的0-2参数,但得到了3哪一行给出了该错误?在上面的示例中,函数仅使用2个参数SCHECK Update 1,但删除它并没有帮助
.subscribe(result:httpResponse => {
    console.log(result);

  }, error => {
    console.error(error);

  });
  GetBList() {
    this.ListLoader = true;
    var url = this.baseurl + 'api/GeneratePDF/GetList/';
    this.http.get(url)
      .toPromise()
      .then((result: HttpResponse <PendingListBWise[]>) => {
        this.BList = result;
        this.ListLoader = false;
      })
      .catch(error => {
        this.ListLoader = false;
        console.error(error);
      }); 
  }