Ways to pass a class list from a client to a webmethod using AJAX

I have a list of client-side classes in TypeScript that I need to send to a web method. Here is my TypeScript code:

  class MakeReportData {
    LocalName: string;
    FldSi: number;
    ViewSi:number;
    TypeName:string ;
    CheckBoxshow :boolean   ;
    CheckBoxFilter:boolean;
}

Below is my Ajax code:

  var temp: MakeReportData[] = [];
        for (var i = 0; i < $scope.myData.ReportDetail.length; i++) {
            var rep: MakeReportData=new MakeReportData();
            rep.LocalName = $scope.myData.ReportDetail[i].LocalName;
            rep.FldSi = $scope.myData.ReportDetail[i].FldSi;
            rep.ViewSi = $scope.myData.ReportDetail[i].ViewSi;
            rep.TypeName = $scope.myData.ReportDetail[i].TypeName;
            rep.CheckBoxshow = $scope.myData.ReportDetail[i].CheckBoxshow;
            rep.CheckBoxFilter = $scope.myData.ReportDetail[i].CheckBoxFilter;
            temp.push(rep);
        }
        var tedata = JSON.stringify({ itm: temp });
        alert(tedata);
        $.ajax({
            type: "POST",
            url: "MakeReport.aspx/GetList",
            contentType: "application/json; charset=utf-8",
            data: tedata , 
            dataType: "json",
            success: function (data) {
                alert(data.d);
            },
            error: function (data, status, jqXHR) {
                alert(status);
                alert(jqXHR);
            }
        });

Here is my web method:

 [WebMethod]
    public static string GetList(MakeReportData[] itm)
    {
        return "";
    }

And here is the C# class I am using:

 public class MakeReportData
{
    public string LocalName { get; set; }
    public int FldSi { get; set; }
    public int ViewSi { get; set; }
    public string TypeName { get; set; }
    public bool CheckBoxshow     { get; set; }
    public bool CheckBoxFilter { get; set; }

}

My issue is that the web method is not being called when I try to send the list of MakeReportData objects.

Answer №1

This was created by me personally. All that is required is to change the webmethod's input to a list as shown below:

 public static string ConvertToList(List<GenerateReportData> items)
    {
        return "";
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Interactive calendar using Php and Javascript/Ajax

Currently, I am working on a PHP calendar and have integrated Javascript/Ajax functionality to enable smooth scrolling between months without the need for page refresh. Interestingly, the calendar displayed as expected before implementing Javascript/Ajax, ...

Best practices for initializing model objects in a Redux or NgRx application architecture

Context: The development team is currently working on a sophisticated REST-based web application using Angular and the @ngrx library for managing state effectively. In order to represent entities retrieved from the server, such as accounts and users, we ...

Show an error message if the email feature is not functioning

I am currently developing an Email verification script that utilizes AJAX. The goal is to display an error bar with the respective error message when a user enters a false or invalid email address. If the email is valid and linked to an active account, an ...

Validating forms using TypeScript in a Vue.js application with the Vuetify

Currently, I am attempting to utilize Vue.js in conjunction with TypeScript. My goal is to create a basic form with some validation but I keep encountering errors within Visual Studio Code. The initial errors stem from my validate function: validate(): v ...

What could be causing my Internet Explorer progress bar to continue loading after every second page load?

I am encountering an issue that is puzzling me. On a rather straightforward ASP.NET page containing a gridview and some buttons, whenever I click a button to refresh the grid by rebinding it and performing a postback, something odd occurs. The IE progress ...

WordPress AJAX code encountered a http400 Bad Request

I've recently started delving into website development and am currently working on a WordPress site. The issue I'm facing is similar to another query on SO, but that question doesn't involve jQuery.AJAX; instead, it utilizes jQuery.post with ...

Create a new list in Rails 6 that dynamically updates based on the selection made in the first list

I am in the process of developing an innovative application that will showcase two distinct lists, with the second list being generated dynamically based on the user's selection from the first list. This dynamic rendering will occur seamlessly on the ...

Is there a way to show the time in a data table? Right now all it displays is "Obj obj

My data table is not displaying the correct information. Here is what my data table shows In my EmployeeSettings Controller, I am trying to retrieve data from the database table. However, I am encountering an error where it says "Cannot convert System.Ti ...

Is it possible to activate a ModalPopupExtender by clicking on a GridView's edit button in ASP.net?

Is it possible to trigger a modal pop-up from the auto-generated Edit button in a GridView control? Could someone offer guidance or resources on how to accomplish this? ...

Retrieving a data type from the key values of deeply nested objects

I'm currently working with JSON data that contains nested objects, and my goal is to extract the unique set of second-level keys as a type. For instance: const json = { 'alice': { 'dogs': 1, 'birds': 4 ...

Transferring data from the Server-Side dataTable to a modal | Creating a personalized row button for dataTable

I have integrated a tutorial from datatables.net into my test page, which can be found at this link: . However, I am facing an issue where I am unable to pass selected data into a modal, and the modal does not open at all. EDIT: Here is the code snippet f ...

Sending data to Dialog Component

While working on implementing the dialog component of material2, I encountered a particular issue: I am aiming to create a versatile dialog for all confirmation messages, allowing developers to input text based on business requirements. However, according ...

Storing information in a database using serialization and PHP

In my project, I am using the serialize method to transfer data from one page to another via AJAX. Here is how I do it: var txtCoursesNamewith = $('#with').serialize(); On the PHP page, I retrieve the data like this: $txtCoursesNamewith = ($_P ...

Can I assign a custom form id before manually triggering submission using AJAX?

I have developed an interesting code snippet that uses AJAX to submit a form only if the form has an ID attached to it. $(document).delegate('form', 'submit', function(event) { var $form = $(this); var id = $form.attr('id& ...

How can we guide the user to a different page when a particular result is retrieved by AJAX?

Whenever my PHP function makes a database call, I receive multiple results. The ajax then displays these results in a div element. My question is: How can I redirect the user to the next page once I obtain a specific result from the PHP function? Current ...

When testing my jQuery locally, it runs smoothly. However, upon uploading it to my website, I encounter some issues where it

After successfully running my webpage on localhost, I encountered an issue when uploading it to my website. Only a portion of the code seems to be executing properly. I have included the following jquery function in my script and there are no reported err ...

Sending a JS function to a PHP script

I've been incorporating the Soundcloud API into my project and successfully implemented their record button on my website. Once the upload is completed, the code generates the URL of the newly created soundcloud file. My goal now is to pass that URL ...

What is the proper way to confirm the authenticity of a captcha code

hey there, I'm struggling with my captcha code. The issue is that it still accepts wrong captchas when entered in the input box. Can someone guide me on how to validate the wrong captcha entry? Here's my form code: <p class="Captcha" style=" ...

Tips for ensuring only one property is present in a Typescript interface

Consider the React component interface below: export interface MyInterface { name: string; isEasy?: boolean; isMedium?: boolean; isHard?: boolean; } This component must accept only one property from isEasy, isMedium, or isHard For example: <M ...

The method IAuthenticationManager.Challenge is failing to properly execute the ExternalLoginCallback function

I am encountering difficulties with enabling Social login on our current ASP.NET MVC website project. The regular customer login, which uses our custom database, is functioning properly. However, the Challenge method on the IAuthenticationManager is failin ...