我正在尝试将整数数组值从angular 7应用程序传递到我的asp.net Web api端点。但是,端点参数为null。如果您在下面看到结果对象,则在插入之后结果对象将收到新创建的ID,并且我将该结果对象值传递给服务器端。我可以看到结果对象中填充了这些值。有人可以告诉我为什么端点不接收整数数组。到端点的请求看起来像这样
http://localhost:56888/api/documentupload/detailsByIds/121,124,125
角度端点调用
public createDocument() {
const documents: IDocumentDetails[] = this.files.map(doc => {
return { // notice just a curly bracket, and in the same line with 'return'
file: doc.fileDropEntry.fileEntry,
documentTypeId: doc.selectedDocumentItem.Id,
name: doc.name,
documentDate: doc.selectedDate
};
});
this.documents = { managerStrategyId: 0, documentDetails: null };
this.documents.managerStrategyId = this.ManagerStrategyId;
this.documents.documentDetails = documents;
this.documentUploadService.createDocumentUpload(this.documents)
.then((result) => {
if (result) {
this.getDocumentUploadDetailsByIds(result);
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(id) {
if (this.ManagerStrategyId != null) {
this.Loading = true;
this.initGrid();
this.documentUploadService.getDocumentUploadDetailsByIds(id)
.subscribe(data => {
this.DocumentUploadDetails = data;
this.Loading = false;
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
}
getDocumentUploadDetailsByIds(documentIds: number[]) {
return this.mgr360CommonService.httpGet('/api/documentupload/detailsByIds/' + documentIds);
}
asp.net webapi
[HttpGet]
[Route("api/documentupload/detailsByIds/{id}")]
public IHttpActionResult DetailsByIds(int[] id)
{
var viewModel = GetDocumentUploadDetailsByIds(id);
return Ok(viewModel);
}
private DocumentUploadViewModel GetDocumentUploadDetailsByIds(int[] id)
{
var docVM = new DocumentUploadViewModel();
var docSvc = GetViewService<V_DOCUMENT>();
var docs = docSvc.Where(x => id.Contains(x.ID)).ToList();
if (docs != null)
{
docVM.DocumentEntities.AddRange(docs.Select(x => new DocumentUploadEntities()
{
DocumentId = x.ID,
DocumentName = x.NAME,
DocumentTypeId = x.DOCUMENT_TYPE_ID,
DocumentTypeName = x.DOCUMENT_TYPE_NAME,
ManagerStrategyId = x.MANAGERSTRATEGY_ID,
ManagerStrategyName = x.STRATEGY_NAME,
DocumentDate = x.DOCUMENT_DATE.HasValue
? x.DOCUMENT_DATE.Value.ToString("MMM dd, yyyy")
: string.Empty,
}).OrderBy(x => x.DocumentCreated));
}
return docVM;
}