我正在使用jQuery的自动完成功能。当我试图检索超过17000条记录的列表(每个记录不会超过10个字符长度)时,它超过了长度并抛出错误:

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

我可以在web.config中设置maxJsonLength的无限长度吗?如果不是,我可以设置的最大长度是多少?


注意:这个答案只适用于Web服务,如果你从Controller方法返回JSON,请确保你也阅读了下面的SO答案:https://stackoverflow.com/a/7207539/1246870


MaxJsonLength属性不能无限制,是一个默认为102400 (100k)的整数属性。

你可以在你的web.config中设置MaxJsonLength属性:

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

您可以在web中配置json请求的最大长度。配置文件:

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

maxJsonLength的缺省值是102400。更多详细信息,请参见MSDN页面:http://msdn.microsoft.com/en-us/library/bb763183.aspx


问题是你是否真的需要返回17k条记录?您打算如何处理浏览器中的所有数据?用户无论如何都不会滚动17000行。

更好的方法是只检索“前几条”记录,并根据需要加载更多记录。


似乎没有“无限”的价值。默认值是2097152个字符,相当于4 MB的Unicode字符串数据。

正如已经观察到的,在浏览器中很难很好地使用17000条记录。如果您正在呈现一个聚合视图,那么在服务器上进行聚合并在浏览器中只传输摘要可能会更有效。例如,考虑一个文件系统浏览器,我们只看到树的顶部,然后在向下钻取时发出进一步的请求。每个请求中返回的记录数量相对较少。树视图表示可以很好地用于大型结果集。


如果,在实现上述添加到您的网页。config,你会得到一个“无法识别的配置部分system.web.extensions”。的错误,然后尝试将此添加到您的网页。<ConfigSections> section中的config:

            <sectionGroup name="system.web.extensions" type="System.Web.Extensions">
              <sectionGroup name="scripting" type="System.Web.Extensions">
                    <sectionGroup name="webServices" type="System.Web.Extensions">
                          <section name="jsonSerialization" type="System.Web.Extensions"/>
                    </sectionGroup>
              </sectionGroup>
        </sectionGroup>

如果你正在使用MVC 4,一定要看看这个答案。


如果你仍然收到错误:

在web.config中将maxJsonLength属性设置为最大值之后 你知道你的数据长度小于这个值 并且您没有使用web服务方法进行JavaScript序列化

你的问题可能是:

MaxJsonLength属性的值仅应用于异步通信层用于调用Web服务方法的内部JavaScriptSerializer实例。(MSDN: ScriptingJsonSerializationSection。MaxJsonLength属性)

基本上,当从web方法调用时,“内部”JavaScriptSerializer尊重maxJsonLength的值;直接使用JavaScriptSerializer(或通过MVC action-method/Controller使用)不尊重maxJsonLength属性,至少不尊重web.config的systemwebextension .scripting. webservices . jsonserialization部分。特别是,Controller.Json()方法不尊重配置设置!

作为一种变通方法,你可以在你的控制器(或任何地方)中执行以下操作:

var serializer = new JavaScriptSerializer();

// For simplicity just use Int32's max value.
// You could always read the value from the config section mentioned above.
serializer.MaxJsonLength = Int32.MaxValue;

var resultData = new { Value = "foo", Text = "var" };
var result = new ContentResult{
    Content = serializer.Serialize(resultData),
    ContentType = "application/json"
};
return result;

这个答案是我对这个asp.net论坛答案的解释。


我修好了。

//your Json data here
string json_object="........";
JavaScriptSerializer jsJson = new JavaScriptSerializer();
jsJson.MaxJsonLength = 2147483644;
MyClass obj = jsJson.Deserialize<MyClass>(json_object);

它工作得很好。


在MVC 4中,你可以做:

protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding, JsonRequestBehavior behavior)
{
    return new JsonResult()
    {
        Data = data,
        ContentType = contentType,
        ContentEncoding = contentEncoding,
        JsonRequestBehavior = behavior,
        MaxJsonLength = Int32.MaxValue
    };
}

在控制器中。

添加:

对于任何对你需要指定的参数感到困惑的人来说,调用可以是这样的:

Json(
    new {
        field1 = true,
        field2 = "value"
        },
    "application/json",
    Encoding.UTF8,
    JsonRequestBehavior.AllowGet
);

你可以像其他人说的那样在配置中设置它,或者你可以在序列化器的单个实例中设置它,比如:

var js = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };

对于那些有问题的MVC3 JSON自动反序列化的模型绑定和太大,这里有一个解决方案。

将JsonValueProviderFactory类的代码从MVC3源代码复制到一个新类中。 添加一行来更改对象反序列化之前的最大JSON长度。 用修改后的新类替换JsonValueProviderFactory类。

感谢http://blog.naver.com/techshare/100145191355和https://gist.github.com/DalSoft/1588818为我指明了正确的方向,如何做到这一点。第一个站点上的最后一个链接包含解决方案的完整源代码。


刚碰到这个。我有超过6000条记录。我就决定做点传呼。在我的MVC JsonResult端点中,我接受一个页码,它默认为0,所以它是不必要的,就像这样:

public JsonResult MyObjects(int pageNumber = 0)

然后不要说:

return Json(_repository.MyObjects.ToList(), JsonRequestBehavior.AllowGet);

我说:

return Json(_repository.MyObjects.OrderBy(obj => obj.ID).Skip(1000 * pageNumber).Take(1000).ToList(), JsonRequestBehavior.AllowGet);

这很简单。然后,在JavaScript中,不是这样的:

function myAJAXCallback(items) {
    // Do stuff here
}

相反,我说:

var pageNumber = 0;
function myAJAXCallback(items) {
    if(items.length == 1000)
        // Call same endpoint but add this to the end: '?pageNumber=' + ++pageNumber
    }
    // Do stuff here
}

然后把你的记录附加到你一开始用它们做的事情上。或者只是等待所有调用完成,然后将结果拼凑在一起。


如果你从MVC中的MiniProfiler中得到这个错误,那么你可以通过设置属性MiniProfiler. settings . maxjsonresponsesize来增加这个值。默认情况下,该工具似乎忽略配置中设置的值。

MiniProfiler.Settings.MaxJsonResponseSize = 104857600;

礼貌mvc-mini-profiler。


我在ASP中遇到了这个问题。NET Web表单。它完全忽略了网络。配置文件设置,所以我这样做:

        JavaScriptSerializer serializer = new JavaScriptSerializer();

        serializer.MaxJsonLength = Int32.MaxValue; 

        return serializer.Serialize(response);

当然,总的来说,这是一种糟糕的做法。如果您要在web服务调用中发送这么多数据,您应该考虑另一种方法。


我解决了添加以下代码的问题:

String confString = HttpContext.Current.Request.ApplicationPath.ToString();
Configuration conf = WebConfigurationManager.OpenWebConfiguration(confString);
ScriptingJsonSerializationSection section = (ScriptingJsonSerializationSection)conf.GetSection("system.web.extensions/scripting/webServices/jsonSerialization");
section.MaxJsonLength = 6553600;
conf.Save();

你可以把这一行写进Controller

json.MaxJsonLength = 2147483644;

您也可以将这一行写入web.config

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

`

为了安全起见,两者都用。


使用lib \ Newtonsoft.Json.dll

public string serializeObj(dynamic json) {        
    return JsonConvert.SerializeObject(json);
}

WebForms UpdatePanel解决方案:

在Web.config中添加一个设置:

<configuration>
  <appSettings>
    <add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
  </appSettings>
</configuration>

https://support.microsoft.com/en-us/kb/981884

ScriptRegistrationManager类包含以下代码:

// Serialize the attributes to JSON and write them out
JavaScriptSerializer serializer = new JavaScriptSerializer();

// Dev10# 877767 - Allow configurable UpdatePanel script block length
// The default is JavaScriptSerializer.DefaultMaxJsonLength
if (AppSettings.UpdatePanelMaxScriptLength > 0) {
    serializer.MaxJsonLength = AppSettings.UpdatePanelMaxScriptLength;
}  

string attrText = serializer.Serialize(attrs);

如果你仍然得到错误后,web。配置设置如下:

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

    

我是这样解决的:

   public ActionResult/JsonResult getData()
   {
      var jsonResult = Json(superlargedata, JsonRequestBehavior.AllowGet);
      jsonResult.MaxJsonLength = int.MaxValue;
      return jsonResult;
    }

我希望这能有所帮助。


我建议设置为Int32.MaxValue。

JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;

如果这个maxJsonLength值是int,那么它的int有多大32位/64位/16位....我只是想确定我可以设置为我的maxJsonLength的最大值

<scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647">
            </jsonSerialization>
        </webServices>
    </scripting>

我遵循了vestial的答案,得到了这个解决方案:

当我需要将一个大的json发送到控制器中的一个动作时,我会得到著名的“使用json JavaScriptSerializer进行反序列化期间错误”。字符串的长度超过maxJsonLength属性设置的值。\r\n参数名称:输入值提供程序”。

我所做的是创建一个新的ValueProviderFactory, LargeJsonValueProviderFactory,并设置MaxJsonLength = Int32。GetDeserializedObject方法中的MaxValue

public sealed class LargeJsonValueProviderFactory : ValueProviderFactory
{
private static void AddToBackingStore(LargeJsonValueProviderFactory.EntryLimitedDictionary backingStore, string prefix, object value)
{
    IDictionary<string, object> dictionary = value as IDictionary<string, object>;
    if (dictionary != null)
    {
        foreach (KeyValuePair<string, object> keyValuePair in (IEnumerable<KeyValuePair<string, object>>) dictionary)
            LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);
    }
    else
    {
        IList list = value as IList;
        if (list != null)
        {
            for (int index = 0; index < list.Count; ++index)
                LargeJsonValueProviderFactory.AddToBackingStore(backingStore, LargeJsonValueProviderFactory.MakeArrayKey(prefix, index), list[index]);
        }
        else
            backingStore.Add(prefix, value);
    }
}

private static object GetDeserializedObject(ControllerContext controllerContext)
{
    if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
        return (object) null;
    string end = new StreamReader(controllerContext.HttpContext.Request.InputStream).ReadToEnd();
    if (string.IsNullOrEmpty(end))
        return (object) null;

    var serializer = new JavaScriptSerializer {MaxJsonLength = Int32.MaxValue};

    return serializer.DeserializeObject(end);
}

/// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
/// <returns>A JSON value-provider object for the specified controller context.</returns>
/// <param name="controllerContext">The controller context.</param>
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
    if (controllerContext == null)
        throw new ArgumentNullException("controllerContext");
    object deserializedObject = LargeJsonValueProviderFactory.GetDeserializedObject(controllerContext);
    if (deserializedObject == null)
        return (IValueProvider) null;
    Dictionary<string, object> dictionary = new Dictionary<string, object>((IEqualityComparer<string>) StringComparer.OrdinalIgnoreCase);
    LargeJsonValueProviderFactory.AddToBackingStore(new LargeJsonValueProviderFactory.EntryLimitedDictionary((IDictionary<string, object>) dictionary), string.Empty, deserializedObject);
    return (IValueProvider) new DictionaryValueProvider<object>((IDictionary<string, object>) dictionary, CultureInfo.CurrentCulture);
}

private static string MakeArrayKey(string prefix, int index)
{
    return prefix + "[" + index.ToString((IFormatProvider) CultureInfo.InvariantCulture) + "]";
}

private static string MakePropertyKey(string prefix, string propertyName)
{
    if (!string.IsNullOrEmpty(prefix))
        return prefix + "." + propertyName;
    return propertyName;
}

private class EntryLimitedDictionary
{
    private static int _maximumDepth = LargeJsonValueProviderFactory.EntryLimitedDictionary.GetMaximumDepth();
    private readonly IDictionary<string, object> _innerDictionary;
    private int _itemCount;

    public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
    {
        this._innerDictionary = innerDictionary;
    }

    public void Add(string key, object value)
    {
        if (++this._itemCount > LargeJsonValueProviderFactory.EntryLimitedDictionary._maximumDepth)
            throw new InvalidOperationException("JsonValueProviderFactory_RequestTooLarge");
        this._innerDictionary.Add(key, value);
    }

    private static int GetMaximumDepth()
    {
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
            int result;
            if (values != null && values.Length > 0 && int.TryParse(values[0], out result))
                return result;
        }
        return 1000;
     }
  }
}

然后,在Global.asax.cs中的Application_Start方法中,用新的ValueProviderFactory替换ValueProviderFactory:

protected void Application_Start()
{
    ...

    //Add LargeJsonValueProviderFactory
    ValueProviderFactory jsonFactory = null;
    foreach (var factory in ValueProviderFactories.Factories)
    {
        if (factory.GetType().FullName == "System.Web.Mvc.JsonValueProviderFactory")
        {
            jsonFactory = factory;
            break;
        }
    }

    if (jsonFactory != null)
    {
        ValueProviderFactories.Factories.Remove(jsonFactory);
    }

    var largeJsonValueProviderFactory = new LargeJsonValueProviderFactory();
    ValueProviderFactories.Factories.Add(largeJsonValueProviderFactory);
}

来点属性魔法怎么样?

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class MaxJsonSizeAttribute : ActionFilterAttribute
{
    // Default: 10 MB worth of one byte chars
    private int maxLength = 10 * 1024 * 1024;

    public int MaxLength
    {
        set
        {
            if (value < 0) throw new ArgumentOutOfRangeException("value", "Value must be at least 0.");

            maxLength = value;
        }
        get { return maxLength; }
    }

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        JsonResult json = filterContext.Result as JsonResult;
        if (json != null)
        {
            if (maxLength == 0)
            {
                json.MaxJsonLength = int.MaxValue;
            }
            else
            {
                json.MaxJsonLength = maxLength;
            }
        }
    }
}

然后,您可以使用全局过滤器配置或控制器/动作在全局中应用它。


如果你在视图中遇到这类问题,你可以使用下面的方法来解决。这里我用的是牛顿软包装。

@using Newtonsoft.Json
<script type="text/javascript">
    var partData = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Part));
</script>

只需在MVC的动作方法中设置MaxJsonLength属性

JsonResult json= Json(classObject, JsonRequestBehavior.AllowGet);
json.MaxJsonLength = int.MaxValue;
return json;

我们不需要任何服务器端更改。你只能通过web修改这个问题。配置文件 这对我很有帮助。试试这个

<appSettings>
 <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
<add key="aspnet:UpdatePanelMaxScriptLength" value="2147483647" />
</appSettings>  

and   

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


你不需要使用web.config 您可以在传递列表的catch值期间使用short属性 例如 像这样声明一个模型

public class BookModel
    {
        public decimal id { get; set; }  // 1 

        public string BN { get; set; } // 2 Book Name

        public string BC { get; set; } // 3 Bar Code Number

        public string BE { get; set; } // 4 Edition Name

        public string BAL { get; set; } // 5 Academic Level

        public string BCAT { get; set; } // 6 Category
}

这里我用的是短比例 公元前=条形码 BE=图书版本等等


选择ASP。NET MVC 5修复:

(我的答案与上面的mfc答案相似,只是有一些小变化)

我还没准备好改用Json。NET还没有,在我的情况下,错误发生在请求期间。在我的场景中,最好的方法是修改实际的JsonValueProviderFactory,它将修复应用到全局项目,可以通过编辑global.cs文件来完成。

JsonValueProviderConfig.Config(ValueProviderFactories.Factories);

添加一个网页。配置项:

<add key="aspnet:MaxJsonLength" value="20971520" />

然后创建以下两个类

public class JsonValueProviderConfig
{
    public static void Config(ValueProviderFactoryCollection factories)
    {
        var jsonProviderFactory = factories.OfType<JsonValueProviderFactory>().Single();
        factories.Remove(jsonProviderFactory);
        factories.Add(new CustomJsonValueProviderFactory());
    }
}

这基本上是在System.Web.Mvc中找到的默认实现的精确副本,但添加了可配置的web。配置appsetting值aspnet:MaxJsonLength。

public class CustomJsonValueProviderFactory : ValueProviderFactory
{

    /// <summary>Returns a JSON value-provider object for the specified controller context.</summary>
    /// <returns>A JSON value-provider object for the specified controller context.</returns>
    /// <param name="controllerContext">The controller context.</param>
    public override IValueProvider GetValueProvider(ControllerContext controllerContext)
    {
        if (controllerContext == null)
            throw new ArgumentNullException("controllerContext");

        object deserializedObject = CustomJsonValueProviderFactory.GetDeserializedObject(controllerContext);
        if (deserializedObject == null)
            return null;

        Dictionary<string, object> strs = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        CustomJsonValueProviderFactory.AddToBackingStore(new CustomJsonValueProviderFactory.EntryLimitedDictionary(strs), string.Empty, deserializedObject);

        return new DictionaryValueProvider<object>(strs, CultureInfo.CurrentCulture);
    }

    private static object GetDeserializedObject(ControllerContext controllerContext)
    {
        if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
            return null;

        string fullStreamString = (new StreamReader(controllerContext.HttpContext.Request.InputStream)).ReadToEnd();
        if (string.IsNullOrEmpty(fullStreamString))
            return null;

        var serializer = new JavaScriptSerializer()
        {
            MaxJsonLength = CustomJsonValueProviderFactory.GetMaxJsonLength()
        };
        return serializer.DeserializeObject(fullStreamString);
    }

    private static void AddToBackingStore(EntryLimitedDictionary backingStore, string prefix, object value)
    {
        IDictionary<string, object> strs = value as IDictionary<string, object>;
        if (strs != null)
        {
            foreach (KeyValuePair<string, object> keyValuePair in strs)
                CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakePropertyKey(prefix, keyValuePair.Key), keyValuePair.Value);

            return;
        }

        IList lists = value as IList;
        if (lists == null)
        {
            backingStore.Add(prefix, value);
            return;
        }

        for (int i = 0; i < lists.Count; i++)
        {
            CustomJsonValueProviderFactory.AddToBackingStore(backingStore, CustomJsonValueProviderFactory.MakeArrayKey(prefix, i), lists[i]);
        }
    }

    private class EntryLimitedDictionary
    {
        private static int _maximumDepth;

        private readonly IDictionary<string, object> _innerDictionary;

        private int _itemCount;

        static EntryLimitedDictionary()
        {
            _maximumDepth = CustomJsonValueProviderFactory.GetMaximumDepth();
        }

        public EntryLimitedDictionary(IDictionary<string, object> innerDictionary)
        {
            this._innerDictionary = innerDictionary;
        }

        public void Add(string key, object value)
        {
            int num = this._itemCount + 1;
            this._itemCount = num;
            if (num > _maximumDepth)
            {
                throw new InvalidOperationException("The length of the string exceeds the value set on the maxJsonLength property.");
            }
            this._innerDictionary.Add(key, value);
        }
    }

    private static string MakeArrayKey(string prefix, int index)
    {
        return string.Concat(prefix, "[", index.ToString(CultureInfo.InvariantCulture), "]");
    }

    private static string MakePropertyKey(string prefix, string propertyName)
    {
        if (string.IsNullOrEmpty(prefix))
        {
            return propertyName;
        }
        return string.Concat(prefix, ".", propertyName);
    }

    private static int GetMaximumDepth()
    {
        int num;
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonDeserializerMembers");
            if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
            {
                return num;
            }
        }
        return 1000;
    }

    private static int GetMaxJsonLength()
    {
        int num;
        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        if (appSettings != null)
        {
            string[] values = appSettings.GetValues("aspnet:MaxJsonLength");
            if (values != null && values.Length != 0 && int.TryParse(values[0], out num))
            {
                return num;
            }
        }
        return 1000;
    }
}

 JsonResult result = Json(r);
 result.MaxJsonLength = Int32.MaxValue;
 result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
 return result;

修复ASP。NET MVC如果你想只修复导致问题的特定操作,请更改以下代码:

public JsonResult GetBigJson()
{
    var someBigObject = GetBigObject();
    return Json(someBigObject);
}

:

public JsonResult GetBigJson()
{
    var someBigObject = GetBigObject();
    return new JsonResult()
    {
        Data = someBigObject,
        JsonRequestBehavior = JsonRequestBehavior.DenyGet,
        MaxJsonLength = int.MaxValue
    };
}

功能应该是一样的,你可以返回更大的JSON作为响应。


基于ASP的解释。NET MVC源代码:你可以检查什么控制器。Json方法在ASP。NET MVC源代码

protected internal JsonResult Json(object data)
{
    return Json(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet);
}

它正在调用其他控制器。Json方法:

protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
{
    return new JsonResult
    {
        Data = data,
        ContentType = contentType,
        ContentEncoding = contentEncoding,
        JsonRequestBehavior = behavior
    };
}

其中传递的contentType和contentEncoding对象为空。所以基本上在控制器中调用return Json(object)相当于调用return new JsonResult {Data = object, JsonRequestBehavior = sonRequestBehavior。DenyGet}。您可以使用第二种形式并参数化JsonResult。

那么当你设置MaxJsonLength属性(默认为null)时会发生什么? 它传递给JavaScriptSerializer。MaxJsonLength属性,然后是JavaScriptSerializer。Serialize方法被调用:

JavaScriptSerializer serializer = new JavaScriptSerializer();
if (MaxJsonLength.HasValue)
{
    serializer.MaxJsonLength = MaxJsonLength.Value;
}

if (RecursionLimit.HasValue)
{
    serializer.RecursionLimit = RecursionLimit.Value;
}

response.Write(serializer.Serialize(Data));

当你不设置serializer的maxjsonlengt属性时,它会取默认值,也就是2MB。


我使用这个,它为剑道网格读取请求工作。

{ 
  //something
   var result = XResult.ToList().ToDataSourceResult(request);
   var rs = Json(result, JsonRequestBehavior.AllowGet);
   rs.MaxJsonLength = int.MaxValue;
   return rs;
}