I am trying to pass an array of integer values to the server webapi endpoint via my angular 7 application getDocumentUploadDetailsByIds method. For some reason the endpoint is receiving null value. I have tried several ways but the parameter of the endpoint is null. Could somebody tell me where I am going wrong
Component
export interface IDocumentIds {
ids: number[];
}
documentIds: IDocumentIds = <IDocumentIds>{};
this.documentUploadService.createDocumentUpload(this.documents)
.then((result) => {
if (result) {
this.documentIds.ids = Object.keys(result).map(k => result[k]);
console.log(this.documentIds);
this.getDocumentUploadDetailsByIds(this.documentIds);
this.setGridOptions();
this.setColumns();
this.notify.success('Documents uploaded Successfully');
}
}).catch(err => {
this.notify.error('An Error Has Occured While uploading the documents');
});
public getDocumentUploadDetailsByIds(documentIds) {
if (this.ManagerStrategyId != null) {
this.Loading = true;
this.initGrid();
this.documentUploadService.getDocumentUploadDetailsByIds(documentIds)
.then((data) => {
if (data) {
this.DocumentUploadDetails = data;
this.Loading = false;
this.notify.success('Documents uploaded Successfully');
}
}).catch(err => {
this.notify.error('An Error Has Occured While uploading the documents');
});
}
}
Service
getDocumentUploadDetailsByIds(documentIds: IDocumentIds) {
return this.mgr360CommonService.httpGetByKey('/api/documentupload/detailsByIds' , documentIds);
}
const httpPostOptions = {
headers:
new HttpHeaders(
{
'Content-Type': 'application/json; charset=utf-8',
}),
withCredentials: true,
};
httpGetByKey(url: string, key: any) {
return this.httpClient.get(this.webApiLocation + url + '/' + key, httpPostOptions)
.pipe(map((response: Response) => {
return response;
}))
.toPromise()
.catch((error: any) => {
this.onError(error);
return Promise.reject(error);
});
}
asp.net web api model
public class DocumentIdViewModel
{
public int[] ids;
}
Endpoint
[HttpGet]
[Route("api/documentupload/detailsByIds/{id}")]
public IHttpActionResult DetailsByIds(DocumentIdViewModel documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
I have also tried setting the parameter to int array of the web method
From angular
this.getDocumentUploadDetailsByIds(this.documentIds.ids);
On server
public IHttpActionResult DetailsByIds(int[] documentIds)
{
var viewModel = GetDocumentUploadDetailsByIds(documentIds);
return Ok(viewModel);
}
DocumentIdViewModel documentIds?id'sinRequest Payload- see this in your browser?