嵌套值对象为空

时间:2018-11-06 17:02:41

标签: angular typescript asp.net-web-api asp.net-web-api2 angular-services

我有一个对象发送到Web Api,一旦它到达我的webAPI,嵌套的对象为null(问题与gatewayRoles有关)

service.ts

processRequest(request: IRequest) {
  var result;
  var objectToSend = JSON.stringify(request);
  var headers = new Headers();
  headers.append('Content-Type', 'application/json');
  console.log('object to send ' + objectToSend);
  return this._http.post(environment.BASE_API_URL + "XXXX", objectToSend, {
      headers: headers
    })
    .map((res: Response) => res.json())
}

IRequest

import { IGatewayRole } from './gateway-role';

export interface IRequest {
  req_id: number;
  req_type_id: number;
  gatewayRole: IGatewayRole[];
}

IGatewayRole

export interface IGatewayRole {
  id: number;
  name: string;
}

JSON

{
  "req_id": 0,
  "req_type_id": 1,
  "gatewayRole": {
    "id": XXXXX,
    "name": "XXXXXXX"
  }
}

webAPI(数据正确传输到了webapi,仅网关角色未映射且值为空

public class Request {
  public int req_id {
    get;
    set;
  }
  public int req_type_id {
    get;
    set;
  }
  public List < IGatewayRole > gatewayRole = new List < IGatewayRole > ();

}

public class IGatewayRole {

  public int id {
    get;
    set;
  }
  public string name {
    get;
    set;
  }

}

[HttpPost]
[Route("API/XXXXXX/")]
[AcceptVerbs()]
public HttpResponseMessage ProcessRequest(Request val) {

  try {
    sp_processRequestResult result = null; //

    return Request.CreateResponse(HttpStatusCode.OK, _modelFactory.Create(result));
  } catch (Exception ex) {
    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
  }
}

0 个答案:

没有答案