无法将对象作为参数传递给Angular 5 get请求

时间:2018-04-14 11:31:46

标签: c# angular angular5 angular-httpclient

我正在使用Angular 5和C#WebAPI进行项目。我在这些环境中工作非常舒服。

我遇到了Angular HTTP GET请求。我试图向我的web api发送一个包含JSON对象和2个字符串变量(共3项)的GET请求。我能够在c#controller中接收2个字符串值,但无法在c#controller中接收JSON对象。

请参阅以下详细信息:

我有一个JSON对象:

{
  "onlineAdmissionFilterArray": [
    {
      "Index": 1,
      "Column": "Time",
      "DataType": "VALUE",
      "ComparisionValue": "LESS THAN",
      "FilterValue": "1",
      "Operator": "AND"
    },
    {
      "Index": 2,
      "Column": "Time",
      "DataType": "VALUE",
      "ComparisionValue": "GREATER THAN EQUAL TO",
      "FilterValue": "3",
      "Operator": "--"
    }
  ],
  "admissionFileName": "APRIL-18-BATCH 01-20180407182256.XLS",
  "_loggedInUserGUID": "490253d0-79f6-4aed-96a9-5a041375d84c"
}

我想要传递给我的C#WebAPI控制器,它是: (请原谅webapi函数的返回类型,我关心的是它的参数)

[HttpGet]
[Route("FilterOnlineAdmissionStudents")]
public string FilterOnlineAdmissionStudents(List<OnlineAdmissionFilterVM> onlineAdmissionFilterArray, string admissionFileName, string _loggedInUserGUID)
{
    return string.Empty;
}

&#34; OnlineAdmissionFilterVM &#34;的C#模型对象是:

public class OnlineAdmissionFilterVM
{
    public string Column { get; set; }
    public string ComparisionValues { get; set; }
    public string DataType { get; set; }
    public string FilterValue { get; set; }
    public int Index { get; set; }
    public string Operator { get; set; }
}

我的Angular HTTP GET请求代码是:

  public FilterOnlineAdmissionStudents(
    onlineAdmissionFilterArray: OnlineAdmissionFilter[],
    admissionFileName: string,
    _loggedInUserGUID: string,
    httpHeaders: HttpHeaders
  ) {
    return this.httpClient.get(this.apiUrl + 'api/admission/online/FilterOnlineAdmissionStudents',
      {
        headers: httpHeaders,
        params: new HttpParams()
          .set('onlineAdmissionFilterArray', 'test')
          .set('admissionFileName', admissionFileName)
          .set('_loggedInUserGUID', _loggedInUserGUID)
      }
    );
  }

我相信我犯了一些愚蠢的错误,或者我的代码格式不正确。 任何人都可以帮助我吗?

0 个答案:

没有答案