Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How best to send multiple id's from Angular to ANZ MVC? #3822


User avatar
0
dparizek created

I have a JS delete function that works fine:

vm.deleteIssue = function (issue) {
                abp.message.confirm(
                    app.localize('IssueDeleteWarningMessage', issue.id, issue.label),
                    function (isConfirmed) {
                        if (isConfirmed) {
                            issueService.deleteIssue({
                                id: issue.id
                            }).then(function () {
                                vm.getIssues();
                                abp.notify.success(app.localize('SuccessfullyDeleted'));
                            });
                        }
                    }
                );
            };

and now I am trying to add a way to delete multiple items at once:

vm.bulkDeleteIssues = function () {
                abp.message.confirm(
                    app.localize('BulkDeleteWarningMessage'),
                    function (isConfirmed) {
                        if (isConfirmed) {
                            vm.selectedIssues = $scope.gridApi.selection.getSelectedRows();
                            var issueIds = [];
                            for (var index in vm.selectedIssues) {
                                issueIds.push(vm.selectedIssues[index].id);
                            }
                            console.log("issueIds:");
                            console.log(issueIds);
                            issueService.bulkDeleteIssues({
                                ids: issueIds
                            }).then(function () {
                                vm.getIssues();
                                abp.notify.success(app.localize('SuccessfullyDeleted'));
                            });
                        }
                    }
                );
            };

my app service has this:

public async Task BulkDeleteIssues(EntityDto[] ids)
        {
            foreach (EntityDto id in ids)
            {
                await DeleteIssue(id);
            }
        }

How should I best package the array of id's that I want to delete? In the case above I get back a 400 Bad Request:

angular.js:12433 POST http://localhost:6240/api/services/app/issue/BulkDeleteIssues 400 (Bad Request)
(anonymous) @ angular.js:12433
sendReq @ angular.js:12178
serverRequest @ angular.js:11930
processQueue @ angular.js:16689
(anonymous) @ angular.js:16733
$eval @ angular.js:18017
$digest @ angular.js:17827
(anonymous) @ angular.js:18056
completeOutstandingRequest @ angular.js:6131
(anonymous) @ angular.js:6411
setTimeout (async)
Browser.self.defer @ angular.js:6409
$evalAsync @ angular.js:18054
(anonymous) @ angular.js:16561
scheduleProcessQueue @ angular.js:16733
then @ angular.js:16658
chainInterceptors @ angular.js:11858
$http @ angular.js:11845
bulkDeleteIssues @ GetAll?type=angular&v=636403114446312803:85
(anonymous) @ index.js:230
(anonymous) @ abp.sweet-alert.js:99
T @ sweet-alert.min.js:1
abp.js:350 ERROR: 
abp.js:350 {code: 0, message: "Your request is not valid!", details: "The following errors were detected during validation.
↵ - 
↵", validationErrors: Array(1)}

and I am unsure how to debug what is happening during validation. Also tried with a list on the server side... public async Task BulkDeleteIssues(List<EntityDto> ids)

I imagine I am doing something really stupid and not understanding how it works to go from JS to server side code?

Any advice for this newbie appreciated!


2 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    hi

    there's problem binding object "EntityDto[] ids" with "issueIds". Beware that EntityDto is class, not a primitive int. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Application/Services/Dto/EntityDto.cs">https://github.com/aspnetboilerplate/as ... tityDto.cs</a>

    So what you have to do is

    public async Task BulkDeleteIssues(int[] ids)
            {
                foreach (EntityDto id in ids)
                {
                    await DeleteIssue(id);
                }
            }
    
  • User Avatar
    0
    dparizek created

    @alper THANK YOU!