I am sending my data in a put request from angular 7 to webapi put method in dotnetcore webapi. But every time I am getting null
instead of actual values.
see the below 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
}
Solved it by de-serializing data before posting it. The problem was with the Cosigner model, as shown above it is a JSON serialized object but controller expects it to be a normal object of Cosigner type. that's why controller rejects the posted data and shows null.