无法使用参数调用网络方法

问题描述 投票:0回答:1

我在C#中有一个Web方法,当它没有参数时,我称该Web方法中的断点。

    [WebMethod]
    public static string GetIDForDownloadExcel()
    {
        ChartEdit cd = new ChartEdit();
        Guid clientID = Guid.NewGuid();
        return JsonConvert.SerializeObject(new { ClientID = clientID, filename = "ExportToExcel" });
    }

我使用以下代码称呼它。

         function GetReportID() {                
            $.ajax({
                type: "POST",
                url: '<%= ResolveUrl("ChartEdit.aspx/GetIDForDownloadExcel") %>',
                data: JSON.stringify({ ind: indicatorsIds, loc: locationsIds }),
                contentType: "application/json",
                dataType: "json",
                success: function (data) {
                    alert('Data: ' + data.d);
                },
                error: function (xhr, status, error) {
                    alert(xhr.responseText);
                }
            });

您可以看到,网络方法没有参数。可以在该方法中达到断点。然后,我希望web方法接收在Ajax中传递的json数据(data:JSON.stringify({ind:indicatorIds,loc:locationIds}),我将WebMethod更改为以下具有参数的方法。

    [WebMethod]
    public static string GetIDForDownloadExcel(string ind,string loc)
    {
        ChartEdit cd = new ChartEdit();
        Guid clientID = Guid.NewGuid();

        return JsonConvert.SerializeObject(new { ClientID = clientID, filename = "ExportToExcel" });
    }

但是,无法再次访问该Web方法,它无法达到该方法中的断点。如何调用可以接收json中传递的数据的网络方法?

我在C#中有一个Web方法,当它没有参数时,我称它在Web方法中到达一个断点。 [WebMethod]公共静态字符串GetIDForDownloadExcel(){ChartEdit cd = new ...

c# webmethod
1个回答
0
投票

我以ajax打印错误响应文本。如下:

© www.soinside.com 2019 - 2024. All rights reserved.