【问题标题】:Json string length exceeds maximum on asp.net web formsJson 字符串长度超过 asp.net 网络表单上的最大值
【发布时间】:2016-04-07 16:58:42
【问题描述】:

我正在尝试使用以下代码在 Web 表单页面中显示 Telerik 下拉列表

private void LoadCustomerControl()
   {
       try
       {
           IControlPanelPersistenceProvider persistenceProvider = new ControlPanelDatabaseProvider();
           List<CustomerDataGrid> customerCollection = persistenceProvider.ListCustomerGrid(false);
           if (customerCollection != null && customerCollection.Count != 0)
           {
               cboCustomer.DataSource = null;
               cboCustomer.DataSource = customerCollection;
               cboCustomer.DataBind();
           }
           else
           {
               //TODO add here message
               m_btnSubbmit.Visible = false;
               m_btnModifyCustomer.Visible = false;
           }
       }
       catch (Exception ex)
       {

           string excep = ex.ToString();
           //TODO add log here
       }
   }

问题是我得到的列表非常大,然后它在浏览器中引发了这个错误

异常消息:使用序列化或反序列化时出错 JSON JavaScriptSerializer。字符串长度超过 在 maxJsonLength 属性上设置的值。

我已经尝试添加到网络配置中

<configuration>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483644 "/>
      </webServices>
    </scripting>
  </system.web.extensions>
</configuration>

我还尝试新建一个 javascriptserializer 并将其 maxjsonlength 设置为 Int32.MaxLength,序列化数据源,然后反序列化回 CustomerDataGrid 列表,但没有任何效果。

对该 LoadCustomerControl 的调用是通过

完成的
if (Request.QueryString.Get("customerId") != null && Request.QueryString.Get("customerId").Length > 0)
           {
               //Is comming from CustomerPage, display the customer
               LoadCustomerControl();
               cboCustomer.SelectedValue = Request.QueryString.Get("customerId");
               cboCustomer.Text = GetCustomerName(int.Parse(Request.QueryString.Get("customerId").ToString()));
               m_btnModifyCustomer.Visible = true;
           }
}

谢谢,

【问题讨论】:

    标签: c# asp.net json


    【解决方案1】:

    尝试在 appsettings 中添加以下内容

    【讨论】:

    • 忘了说也试过了,同样的运气
    • 看看这个stackoverflow线程。可能有帮助。 stackoverflow.com/questions/9509721/…
    • 非常感谢,问之前看到了。已经花了几个小时,但似乎没有任何解决办法。
    • 我还在某处看到您可能需要在 appsettings 中设置
    猜你喜欢
    • 2013-08-15
    • 2013-12-24
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    相关资源
    最近更新 更多