0

I am working in ASP.NET Boilerplate (ABP) and AngularJS. I am using controllers (to upload files) with Kendo upload on frontend. To access controller I am using clicking kendo button clicking it like:

($("#files").data("kendoUpload")).options.async = vm.uploadOptions(onUpdate);
$('.k-upload-selected').click();

Function vm.uploadOptions(onUpdate) takes list of Ids and returns retObject like

var retObject = { saveUrl: '/ControllerName/ActionName?id=15&id=16', autoUpload: false, batch: true }

Now the actual question: When I assign saveUrl in retObject like above or like

retObject.saveUrl = '/ControllerName/ActionName?id=195&id=196&id=197'

(ids hardcoded), the controller is entered (I have a breakpoint there) and I have a C# List with two elements.

When I assign url like:

vm.url = '/ControllerName/ActionName?fileId=' + fileIds[0];
len = fileIds.length;
for (var i = 1; i < len; i++) {
    vm.url += '&fileId=' + fileIds[i];
}
retObject.saveUrl = vm.url;

the controller is not entered.

Finally (this is what I use in code now), when I assign like

vm.url = '?fileId=' + fileIds[0];
len = fileIds.length;
for (var i = 1; i < len; i++) {
    vm.url += '&id=' + fileIds[i];
}
retObject.saveUrl = '/ControllerName/ActionName' + vm.url;

it does work - controller is entered with a proper list of ids.

When I copied dynamically generated (not working) string and assigned it as hardcoded it started working. Why it happens, I mean: why exactly the same string initialized in different ways makes different results?

Dawid
  • 153
  • 3
  • 18
  • Isn't the difference that the first example just uses a query paramter with the name `fileId` and the second example just uses `fileId` for the first and `id` for the subsequent? Maybe the controller method just has `id` defined as parameter and no `fileId` parameter so the first url is not bound to the route? Or it might be a routing issue? – mortb Sep 08 '17 at 15:05
  • suggestion: replace code with `vm.url = '/ControllerName/ActionName? + fileIds.join('&');` no need for loop – mortb Sep 08 '17 at 15:07
  • No, fileId and id difference is only the matter of my bad rewriting code into stackoverflow. I can assure you this is not the matter of fileId/Id, the controller has fileId and such URL has always been provided. Ok, thanks for suggestion. – Dawid Sep 09 '17 at 19:15

0 Answers0