[英]Parameter values in Web api is always null
我正在将我的数据从 angular 7 的 put 请求发送到 dotnetcore webapi 中的 webapi put 方法。 但每次我得到null
而不是实际值。
见下面的snipets。
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": []
}
put(path: string, body: Object = {}): Observable<any> {
return this.httpClient.put(`${path}`,JSON.stringify(body),this.httpOptions);
}
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 类型的普通对象。 这就是为什么控制器拒绝发布的数据并显示为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.