2012-08-01 62 views
1

我使用telerik網格來顯示來自sql db的數據...當我顯示超過3500行時,它會返回:使用JSON JavaScriptSerializer進行序列化或反序列化時出現錯誤。字符串的長度超過maxJsonLength屬性中設置的值。Telerik MVC Grid - 多個數據行結果

無處不在互聯網和Telerik Troubleshooting manual也寫道,原因是編輯web.config。它並沒有幫助我...我試着返回這樣的數據:

JavaScriptSerializer serializer = new JavaScriptSerializer { MaxJsonLength = 536870912, RecursionLimit = 100 }; 
return new ContentResult() 
{ 
    Content = serializer.Serialize(data), 
    ContentEncoding = Encoding.UTF8 
}; 

當我作爲ContentResult返回數據,過濾和排序停止工作。

我嘗試這個解決方案也:http://anyrest.wordpress.com/2011/09/27/large-json-result-for-teleriks-mvc-grid/並沒有幫助我......

這是從我的控制器代碼:

[GridAction, POST("GridData")] 
public ActionResult _Index() 
{ 
    var data = GetExclusionsDataCollection(); 

    return View(new GridModel { Data = data }); 
} 

謝謝, 大衛

回答

1

我接觸Telerik的支持,現在我可以分享我的問題的原因...

link到Telerik的代碼庫。重要的部分是將行添加到global.asax.cs中。他們的解決方案的這部分是不是在大多數我所看到的其他解決方案...

DI.Current.Register<IGridActionResultFactory>(() => new MyCustomGridActionResultFactory()); 

此行導致ovveride默認Telerik的功能和積極自定義JSON結果...

-David

0

嘗試增加web.config中的maxRequestLength

<system.web> 
<httpRuntime requestValidationMode="2.0" maxRequestLength="VALUE" /> 
</system.web> 

哪裏值將被設置爲int.maxvalue或int64.maxvalue