3

网络方法:

   <WebMethod()>
   Public Shared Function Pcpacking() As IEnumerable(Of Packing)
   Dim db As New STOREEntities
   Return db.PC_PACKING_HISTORIES. _
   Where(Function(q) q.PACK_DATE > "1388/11/07"). _
   Select(Function(q) New Packing _
              With {.Packdate = q.PACK_DATE,
                    .Packserialnumber = q.PACK_SERIAL_NUMBER,
                    .Netweight = q.NET_WEIGHT,
                    .Packusername = q.PACK_USER_NAME}).ToList()
   End Function

脚本:

$(function () {
       $("#grid").kendoGrid({
           height: 200,
           columns: [
                { field: "Packserialnumber", width: "150px" },
               { field: "Netweight", width: "50px" },
               { field: "Packusername", width: "150px" },
               { field: "Packdate", width: "100px" }
           ],
           editable: false,
           dataSource: {
               schema: {
                   data: "d",
                   model: {
                       id: "Packserialnumber",
                       fields: {
                           Packserialnumber: { editable: false, nullable: true },
                           Netweight: { type: "number", validation: { required: true, min: 1} },
                           Packusername: { validation: { required: true} },
                           Packdate: { validation: { required: true} }
                       }
                   }
               },
               batch: false,
               transport: {
                   read: {
                       url: "Default.aspx/Pcpacking",
                       contentType: "application/json; charset=utf-8",
                       type: "POST"
                   }
               }
           }
       });
   });

在这种情况下(PACK_DATE > "1388/11/07" 366 记录)一切正常。但是当我将日期更改为 1388/11/06 1260 记录或 1388/11/05 5460 记录或...发生以下错误:

{"Message":"使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength 属性设置的值。","StackTrace":" 在 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(对象 obj、StringBuilder 输出、SerializationFormat serializationFormat)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n 在 System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext上下文、WebServiceMethodData 方法数据、IDictionary`2 rawParams)\r\n
在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext 上下文,WebServiceMethodData 方法数据)”,“ExceptionType”:“System.InvalidOperationException”}

我认为剑道网格不支持大量数据。有什么建议吗?
对不起,我的英语不好。

4

2 回答 2

2

问题实际上是默认情况下,如果生成的 JSON 字符串大于 100 kB,.NET JSON 序列化程序会引发异常。显然,发送数千条记录大于限制。您可以更改此设置,但我不建议您将其用于您的应用程序。

相反,将网格配置为一次请求小块数据。看起来您可以配置 Kendo Grid 以在滚动时加载更多数据

$("#grid").kendoGrid({
    dataSource: {
        type: "odata",
        serverPaging: true,
        serverSorting: true,
        pageSize: 100,
        transport: {
            read: {
                url: "Default.aspx/Pcpacking",
                contentType: "application/json; charset=utf-8",
                type: "POST"
            }
        }
    },
    scrollable: {
        virtual: true
    },

    ...
});

您的服务器端脚本必须处理 Kendo 发送的(top发送多少条记录)和skip(从哪里开始)参数。

于 2012-05-19T16:12:09.967 回答
0
$(function () {
       $("#grid").kendoGrid({
           height: 200,
           columns: [
                { field: "Packserialnumber", width: "150px" },
               { field: "Netweight", width: "50px" },
               { field: "Packusername", width: "150px" },
               { field: "Packdate", width: "100px" }
           ],
           editable: false,
           dataSource: {
               schema: {
                   data: "d",
                   model: {
                       id: "Packserialnumber",
                       fields: {
                           Packserialnumber: { editable: false, nullable: true },
                           Netweight: { type: "number", validation: { required: true, min: 1} },
                           Packusername: { validation: { required: true} },
                           Packdate: { validation: { required: true} }
                       }
                   }
               },
               batch: false,
               transport: {
                   read: {
                       url: "Default.aspx/Pcpacking",
                       contentType: "application/json; charset=utf-8",
                       dataType: "json"
                   }
               }
           }
       });
   });
于 2013-12-19T07:13:40.930 回答