0

I'm calling a webservice and passing back a List<> from an Ajax call. Now I need to get that value and pass it to code-behind file with a data type of List<>. Can this be done and if so how can I do it. I've looked here for the solution but I didn't see anything like this. I tried a HiddenField but I get an error that it can't convert from List<> to string.

function GetEnrollmentRecords() {
    IsLoading = true;

    $.ajax({
        type: "POST",
        url: "EnrollmentService.asmx/GetEnrollmentRecords",
        data: "{qryLastRecord: " + LastRecord  + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnGetEnrollmentRecordsSuccess,
        failure: function (response) {
            IsLoading = false;
        
        },
        error: function (response) {
            IsLoading = false;
       
        }
    });
}

function OnGetEnrollmentRecordsSuccess(response) {
    var responseObject = response.d;

    LastRecord = responseObject.intLastRecord;
    var hdnfldVariable = document.getElementById('ListOfEnrollments');
    hdnfldVariable.value = Object.values(responseObject.enrollments);

    IsLoading = false;
}
NewbieCoder
  • 75
  • 1
  • 8
  • _"from an Ajax call"_ please share that? _"Can this be done"_ - probably, what have you tried so far? - Please update the question with a [mcve] – evolutionxbox May 27 '21 at 15:39
  • Sounds like you are trying to use the list to populate the hidden field directly. A hidden field can only contain a string. So you have to convert it. A popular way to do it would be to convert the list to json. See [convert list to json format - quick and easy way](https://stackoverflow.com/a/6366183/2791540) – John Wu May 27 '21 at 15:45

0 Answers0