0

MVC3 (.cshtml ファイル)

$.getJSON(URL, Data, function (data) {

                    document.getElementById('divDisplayMap').innerHTML = data;

                    if (data != null) {
                        $('#myTablesId').show();
                        tdOnclickEvent();

                    }
                    else {
                        $('#myTablesId').hide();
                    }
                }).error(function (xhr, ajaxOptions, thrownError) { debugger; });

サーバー側

 public JsonResult ZoneType_SelectedState(int x_Id, int y_Id)
    {
    JsonResult result = new JsonResult();
     result.Data = "LongString";//Longstring with the length mention below
    return Json(result.Data,"application/json", JsonRequestBehavior.AllowGet);
    }

サーバー側からは、1194812 以上の長さの文字列を渡しています。しかし、私はエラーが発生しています

"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property."

ASPを助けてください

4

2 に答える 2

2

シリアライザーが処理できるデータの最大長を指定できるようにするカスタム ActionResult を作成できます。

public class MyJsonResult : ActionResult
{
    private readonly object data;
    public MyJsonResult(object data)
    {
        this.data = data;
    }

    public override void ExecuteResult(ControllerContext context)
    {
        var response = context.RequestContext.HttpContext.Response;
        response.ContentType = "application/json";
        var serializer = new JavaScriptSerializer();
        // You could set the MaxJsonLength to the desired size - 10MB in this example
        serializer.MaxJsonLength = 10 * 1024 * 1024;
        response.Write(serializer.Serialize(this.data));
    }
}

そしてそれを使用します:

public ActionResult ZoneType_SelectedState(int x_Id, int y_Id)
{
    string data = "LongString";//Longstring with the length mention below;
    return new MyJsonResult(data);
}
于 2013-10-01T06:11:48.433 に答える
0

Controller以下に示すように、メソッドを更新してみてください。

public JsonResult ZoneType_SelectedState(int x_Id, int y_Id)
{
    var result = Json("LongString", JsonRequestBehavior.AllowGet);
    result.MaxJsonLength = int.MaxValue;
    return result;
}

お役に立てれば...

于 2016-01-26T22:42:36.190 に答える