Base solution for your next web application
Open Closed

Error getting selected items (checked) in grid (JQuery/MVC) #4778


User avatar
0
[email protected] created

We are having a strange problem using ASP.NET Zero version 5.1 (MVC Core+JQuery, framework .NET Standard). When we try to add a member to an existing organizational unit from the popup, the checked users are not detected by the "Add User" JS handler and all the users are passed to the service. It's strange because we didn't change this specific part of your code. I tried an older version of ASP.NET Zero (4.6) and the same code works just fine; the only difference I have spotted is the Datables.js library.

Here are more details: (in _AddMemberModal.js): _modalManager.getModal().find('#btnAddUsersToOrganization').click(function () { _modalManager.setResult(dataTable.rows({ selected: true }).data().toArray()); _modalManager.close(); });

(in OrganizationUnitAppService): [AbpAuthorize(AppPermissions.Pages_Administration_OrganizationUnits_ManageMembers)] public async Task AddUsersToOrganizationUnit(UsersToOrganizationUnitInput input) { foreach (var userId in input.UserIds) { await UserManager.AddToOrganizationUnitAsync(userId, input.OrganizationUnitId); } }

If I run the code with ASP.NET Zero 5.1 the "selected: true" filter of the dataTable.Rows collection is not working; I always get the whole collection in the UsersToOrganizationUnitInput object on the server side. If I don't check any user, I always get the full list of user ids shown on the grid page.

If I run it with ASP.NET Zero 4.6 the "selected: true" filter of the dataTable.Rows collection is working OK; I get the actual list of selected items on the server side; if I don't check any user, I get an empty list as expected.

This is very strange and I already spent some time trying to figure it.

Can you please help ?

Thanks, David


3 Answer(s)
  • User Avatar
    0
    [email protected] created

    If this can help ... I tried to download a brand new demo project of ASP.NET Zero 5.2 (MVC Core + JQuery) and just running it. I was able to reproduce the same bug and the only thing I changed was the connection string. Clicked on "Administration" -> Organization Units, selected an existing OU, clicked on "Add Member", clicked "Save" on the popup without selecting any user. Result: all the users of the page added to the OU !

    Thanks, David

  • User Avatar
    0
    aaron created
    Support Team

    We need datatables.net-select npm package.

    Quick fix

    Add this in OrganizationUnits/Index.cshtml:

    <script src="https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js"></script>
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks guys,

    I have created an issue here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/888">https://github.com/aspnetzero/aspnet-ze ... issues/888</a>. We will fix it for the next release.