[英]“The length of the string exceeds the value set on the maxJsonLength property.” when trying to convert a partial view to string
I am getting the error "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."
我收到错误消息"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."
when trying to convert a MVC partial view to string when the payload exceeds the MaxJsonLength
property. 当有效载荷超过MaxJsonLength
属性时尝试将MVC部分视图转换为字符串时。
How do I go about setting the MaxJsonLength property in this case? 在这种情况下,如何设置MaxJsonLength属性? I've tried setting the <jsonSerialization maxJsonLength="2147483644"/>
property in the web.config, as per this post, but that doesn't have any effect. 我已经尝试设置<jsonSerialization maxJsonLength="2147483644"/>
属性在web.config中,按照这个帖子,但没有任何效果。 I am not entirely where to go from here and looking for a bit of a guidance. 我不完全是从这里去寻找指导的地方。
The code errors on the viewResult.View.Render(viewContext, sw);
viewResult.View.Render(viewContext, sw);
上的代码错误viewResult.View.Render(viewContext, sw);
line below: 下面的行:
protected string ConvertViewToString(string viewName, object model)
{
string razorView = string.Empty;
if (string.IsNullOrWhiteSpace(viewName)) return razorView;
if (model != null && ViewData != null)
{
ViewData.Model = model;
}
if (ControllerContext != null)
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
if (viewResult != null)
{
using (StringWriter sw = new StringWriter())
{
ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
razorView = sw.GetStringBuilder().ToString();
}
}
}
return razorView;
}
The underlying cause of this was due to trying to load too large a result set into the Telerik Kendo grid within the partial view - the Kendo grid was throwing the exeception which is why it was being caught on the viewResult.View.Render(viewContext, sw)
line. 造成这种情况的根本原因是由于试图将太大的结果集加载到部分视图中的Telerik Kendo网格中-Kendo网格引发了误解,这就是为什么它被捕获在viewResult.View.Render(viewContext, sw)
行。 The solution was to break the result set down into smaller manageable chunks. 解决方案是将结果集分解为较小的可管理块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.