Web api 中的参数值始终为空

Parameter values in Web api is always null

我正在从 angular 7 发送请求中的数据到 dotnetcore webapi 中的 webapi put 方法。但是每次我得到 null 而不是实际值。

请参阅以下片段。

发出卖出请求

this.customerService.put(this.customer).subscribe(result => {
    // doing something here
});

控制器中的方法

 [HttpPut]
 [Route("update")]
 public dynamic UpdateCustomer([FromBody]DTO.Customer customer)
{
        // customer is null, instead of getting posted data.
}

数据已发送

{
  "id": 1,
  "identityId": "542d4b93-4afb-4ee0-a433-c0794bb6ce05",
  "identity": {
    "firstName": "John",
    "lastName": "Doe",
    "pictureUrl": null,
    "role": 0,
    "id": "542d4b93-4afb-4ee0-a433-c0794bb6ce05",
    "userName": "JohnDoes@test.com",
    "normalizedUserName": "JOHNDOES@TEST.COM",
    "email": "JohnDoes@test.com",
    "normalizedEmail": "JOHNDOES@TEST.COM",
    "emailConfirmed": false,
    "passwordHash": "AQAAAAEAACcQAAAAEIEt4AjVwpIi0BEuhS7SJFrsa5NAuLn/fuE61Drvgm863cIw5ua+DTl2A/EHsamW+A==",
    "securityStamp": "565e8576-0b33-4613-9843-b032c908e4ba",
    "concurrencyStamp": "43c71a17-680f-45fb-b6b2-8374db1624fa",
    "phoneNumber": "0",
    "phoneNumberConfirmed": false,
    "twoFactorEnabled": false,
    "lockoutEnd": null,
    "lockoutEnabled": true,
    "accessFailedCount": 0
  },
  "location": null,
  "locale": null,
  "gender": null,
  "home_Address": null,
  "residing_Address": null,
  "home_City": null,
  "residing_City": null,
  "residing_State": null,
  "home_State": null,
  "birthDate": null,
  "joiningDate": null,
  "educationDetails": "null",
  "cosigner": "{\"CosignerName\":\"jhg\",\"CosingerPhoneNumber\":78955422,\"CosignerEmploymentStatus\":1,\"CosignerEmail\":\"test@test.com\",\"WorkPermitLeft\":20,\"MonthlySalary\":2500.0,\"Address\":\"mkbgiygyi\"}",
  "bankStatement": null,
  "finance": "null",
  "home_Country": null,
  "residing_Country": null,
  "phone": 0,
  "fax": null,
  "graduationType": null,
  "graduationStream": null,
  "panNumber": 0,
  "postalCode": null,
  "application": []
}

CustomerService.put()

put(path: string, body: Object = {}): Observable<any> {
    return this.httpClient.put(`${path}`,JSON.stringify(body),this.httpOptions);
  }

DTO.Customer

 public class Customer
  {
    public int Id { get; set; }
    public CosignerDetails Cosigner { get; set; }

  // some other properties
  // above props. are of interest among others
  }

public class CosignerDetails{
   public int Id { get; set; }
   public string Name { get; set; }

   // some other properties
}

通过在发布数据之前反序列化数据解决了这个问题。问题出在 Cosigner 模型上,如上所示,它是一个 JSON 序列化对象,但控制器希望它是 Cosigner 类型的普通对象。这就是控制器拒绝发布的数据并显示空值的原因。