I'm struggling with this problem for a long time.
I have a Client app set with Angular 6 and WebApi created with ASP Core 2.1.
For my POST request, I do something like this.
const params = {
TestData: newActions,
ExportAndExecute: true
};
this.httpClient.post('/tests/export', params, {headers: {}}).subscribe((result) => {
console.log(result);
});
where httpClient.post method is :
post(route: string, params: any, headers: object) {
return new Observable<any>(subscriber => {
this.httpClient.post<any>(this.baseUrl + route, params, headers).subscribe((result) => {
subscriber.next(result);
}, (error: Response) => {
this.handleRequestError(error);
});
});
}
My API controller action looks like this:
[HttpPost]
[Route("/api/[controller]/export")]
[Authorize(AuthenticationSchemes = "JwtBearer")]
public async Task<HttpStatusCode> ExportTest( [FromBody] ExportTestModel model)
{
var result = HttpStatusCode.MisdirectedRequest;
}
And model class is:
public class ExportTestModel
{
public List<BsonDocument> TestData { get; set; }
public bool ExportAndExecute { get; set; }
}
I don't know why every time I send the data from a client, it is null in the controller action. I tried to send it as a stringified object, receive in controller as object or JObject but nothing works as expected.
I can add that if I receive data as JObject I can see it properly but I don't want to do it this way.
I feel stupid but maybe someone can point me what I'm doing wrong in my approach.