Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从ASP.NET返回的JSON不与剑道网格绑定_C#_Asp.net_Kendo Grid - Fatal编程技术网

C# 从ASP.NET返回的JSON不与剑道网格绑定

C# 从ASP.NET返回的JSON不与剑道网格绑定,c#,asp.net,kendo-grid,C#,Asp.net,Kendo Grid,我可以使用以下代码成功地对我的web方法进行AJAX调用,web方法返回粘贴在下面的JSON: 我的Web方法 [WebMethod] public static string GetJson() { string query = "SELECT top 10 cast(ClientUID as varchar) ClientUID FROM <tablename>"; SqlCommand cmd = new SqlCommand(query); //

我可以使用以下代码成功地对我的web方法进行AJAX调用,web方法返回粘贴在下面的JSON:

我的Web方法

[WebMethod]
public static string GetJson()
{
     string query = "SELECT top 10 cast(ClientUID as varchar) ClientUID FROM <tablename>";
     SqlCommand cmd = new SqlCommand(query);
     // Populate the DataSet.
     DataSet data = GetData(cmd);
     // return the Customers table as JSON.
     DataTable dt = data.Tables[0];
     var returnJSON = (from p in dt.AsEnumerable()
          select new
          {
               ClientUID = p.Field<string>("ClientUID")
           }).ToList();
      var serializer = new JavaScriptSerializer();
      string json = serializer.Serialize(returnJSON);
      return json; 
}
web方法返回的JSON:

[{ClientUID:1}、{ClientUID:2}、{ClientUID:3}、{ClientUID:4}、{ClientUID:5}、{ClientUID:6}、{ClientUID:7}、{ClientUID:8}、{ClientUID:9}、{ClientUID:10}]

使用AJAX调用web方法

<script type="text/javascript">
        $(document).ready(function() {
            $.ajax(
                    {
                        type: "POST",
                        url: "ServeClientCalls.aspx/GetJson",
                        data: {},
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function(msg) {
                        //checking the content return from the above web method
                        $("#msg").html(msg.d); 
                            //Binding to kendo Grid
                            $("#grid").kendoGrid({
                                dataSource: {
                                    data: msg.d,
                                    schema: {
                                        model: {
                                            fields: {
                                                ClientUID: { type: "string" }
                                            }
                                        }
                                    },
                                    pageSize: 20
                                },

                                height: 430,
                                filterable: true,
                                sortable: true,
                                pageable: true,
                                columns: [
                                        { field: "ClientUID" }
                                    ]
                            });
                        },
                        error: function(x, e) {
                            $("#msg").html(x.responseText);
                        }
                    });
        });
    </script>
问题:我的网格没有绑定,只显示标题,而当我以下面提到的方式使用代码时,它是有效的

<script type="text/javascript">
        $(document).ready(function() {
            $.ajax(
                    {
                        type: "POST",
                        url: "ServeClientCalls.aspx/GetJson",
                        data: {},
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function(msg) {
                        //checking the content return from the above web method
                        $("#msg").html(msg.d);
                        **var p = [{ ClientUID: 1 }, { ClientUID: 2 }, { ClientUID: 3 }, { ClientUID: 4 }, { ClientUID: 5 }, { ClientUID: 6 }
                            , { ClientUID: 7 }, { ClientUID: 8 }
                            , { ClientUID: 9 }, { ClientUID: 10}];**
                            //Binding to kendo Grid
                            $("#grid").kendoGrid({
                                dataSource: {
                                    **data: p,**
                                    schema: {
                                        model: {
                                            fields: {
                                                ClientUID: { type: "string" }
                                            }
                                        }
                                    },
                                    pageSize: 20
                                },

                                height: 430,
                                filterable: true,
                                sortable: true,
                                pageable: true,
                                columns: [
                                        { field: "ClientUID" }
                                    ]
                            });
                        },
                        error: function(x, e) {
                            $("#msg").html(x.responseText);
                        }
                    });
        });
    </script>

在schema部分下使用数据:d。这应该行。

如果你想问原始海报你的解决方案是否有效,或者做类似的评论,你应该使用评论,而不是答案的主体