使用JSONJavaScriptSerializer进行序列化或反序列化时出错。字符串的长度超过

时间:2019-03-11 06:30:44

标签: c# json ajax model-view-controller nsjsonserialization

我将下面的代码放在web,config中,但是它不起作用。仍然出现上述错误。

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

在控制器中,我有以下代码

string htmlTable = DataTransformer.ConvertDataTableToHtmlTable(dataTable, "revalidationtable");
            return Json(new { 
                @DataTable = htmlTable, 
                @RevalidationMessage = revalidationMessage, 
                @RevalidationNotes = revalidationNotes, 
                @ModeSelect = modeSelect, 
                @ModeCheck = modeCheck 
            }, JsonRequestBehavior.AllowGet);

我已将控制器代码更改为此,但仍然显示相同的错误

var jsonResult =  Json(new { @DataTable = htmlTable, @RevalidationMessage = revalidationMessage, @RevalidationNotes = revalidationNotes, @ModeSelect = modeSelect, @ModeCheck = modeCheck , JsonRequestBehavior.AllowGet } );
            jsonResult.MaxJsonLength = Int32.MaxValue;
            return jsonResult;

0 个答案:

没有答案