ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 64.4k

can't send text for checkbox selected as array from jQuery ajax reques

Feb 25 2024 2:53 AM

I work on asp.net core razor page . I pass selected id as array success

but my issue selected text value for check box not passed or displayed

Issue happen on this line selectedClassText.push($(this).next('label').text());

when debug action result string[] classidsText it display null .

Exactly i need to pass selected text beside checkbox as array.

razor page .cs that get class id text

    public JsonResult OnGetSubAccountClassName(string[] classIds,string[] classidsText)
{
    var assetsSubAccountName = _IAssetsService.GetJdeAssetSubAccountClassName(classIds);
    AssetCountGeneration.JDEAssetSubAccountClassNameDetails = assetsSubAccountName;
    return new JsonResult(assetsSubAccountName);
}

from jQuery ajax on page cshtml i send selected displayed text by selectedClassText

 $(document).on('change', '.classCheckbox', function () {
      var selectedClassIds = [];
      var selectedClassText = [];
$('.classCheckbox:checked').each(function () {
    selectedClassIds.push($(this).val());
    selectedClassText.push($(this).next('label').text());
});
      console.log("selected items" + selectedClassIds)
      if (selectedClassIds.length > 0) {
          $.ajax({
              url: '?handler=SubAccountClassName',
              type: 'GET',
              traditional: true,
              data: { classIds: selectedClassIds,classidsText:selectedClassText },
              success: function (response) {
                  $('#subClassesList').empty();
                  $('#subClassesContainer').show();
                 
                  var subClassesContainer = $('<div data-class-id="' + selectedClassIds + '"></div>');
                  $.each(response, function (i, item) {
                      $(subClassesContainer).append('<input type="checkbox" class="subclassCheckbox" name="selectedSubClasses" value="' + item.subClassAccountId + '" /> ' + item.subClassAccountName + '<br />');
                  });
                  $('#subClassesList').append(subClassesContainer);
              }
          });

 

 


Answers (1)