在尝试将json字符串放入我的kendo网格时,我一直收到此错误。我在web.config中设置了最大大小
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644">
</jsonSerialization>
</webServices>
</scripting>
我还尝试将其直接添加到控制器中。这就是我生成json字符串的方法
public ActionResult ChangeRequests_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(GetRequests().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
public static IEnumerable<ChangeRequestsVM> GetRequests()
{
var model = CompanyContextFactory.GetContextPerRequest();
var chrwVM = model.ChangeRequestsHDRs.Where(ch=> ch.CompanyID == GlobalVariables.CompanyID).Select(ch=> new ChangeRequestsVM
{
RequestID = ch.RequestID,
CompanyID = ch.CompanyID,
ClientID = ch.ClientID,
EmployeeID = (string.IsNullOrEmpty(ch.EmployeeID)) ? "NA" : ch.EmployeeID,
AssignmentType = ch.AssignmentType,
Key1 = ch.Key1,
Key2 = ch.Key2,
LogonID = ch.LogonID,
ProcessDate = ch.ProcessDate,
ProcessTime = ch.ProcessTime,
ProcessUserID = ch.ProcessUserID,
RequestDate = ch.RequestDate,
RequestExport = ch.RequestExport,
RequestNote = ch.RequestNote,
RequestOrigin = Convert.ToChar(ch.RequestOrigin),
RequestProcess = ch.RequestProcess,
RequestStatus = ch.RequestStatus,
RequestTime = ch.RequestTime,
RequestType = Convert.ToChar(ch.RequestType),
ResponseNote = ch.ResponseNote,
TableName = ch.TableName,
TransferDate = ch.TransferDate,
TransferTime = ch.TransferTime,
TransferUserID = ch.TransferUserID,
dispOrigin = (Convert.ToChar(ch.RequestOrigin) == ChangeRequestOrigin.System) ? "System" : (Convert.ToChar(ch.RequestOrigin) == ChangeRequestOrigin.Client) ? "Client" : "Employee",
dispRequestType = (Convert.ToChar(ch.RequestType) == ChangeRequestType.Insert) ? "Insert" : (Convert.ToChar(ch.RequestType) == ChangeRequestType.Alter) ? "Change" : "Delete",
dispStatus = FieldTranslation.GetEnumDescription(typeof(enChangeRequestStatus), ch.RequestStatus ?? 0)
}).OrderByDescending(ch=> ch.RequestID);
return chrwVM;
}
这是我得到的完整错误。发送的字符串是巨大的,但我不知道如何弄清楚它有多大。我错过了什么让JSON字符串返回而没有错误?
Error during serialization or deserialization using the JSON JavaScriptSerializer.
The length of the string exceeds the value set on the maxJsonLength property
我也是这样试过的
public ActionResult ChangeRequests_Read([DataSourceRequest] DataSourceRequest request)
{
var result = Json(GetRequests().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
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 { result };
var result1 = new ContentResult
{
Content = serializer.Serialize(resultData),
ContentType = "application/json"
};
return result1;
}
public static IEnumerable<ChangeRequestsVM> GetRequests()
{
var model = CompanyContextFactory.GetContextPerRequest();
var chrwVM = model.ChangeRequestsHDRs.Where(ch=> ch.CompanyID == GlobalVariables.CompanyID).Select(ch=> new ChangeRequestsVM
{
RequestID = ch.RequestID,
CompanyID = ch.CompanyID,
ClientID = ch.ClientID,
EmployeeID = (string.IsNullOrEmpty(ch.EmployeeID)) ? "NA" : ch.EmployeeID,
AssignmentType = ch.AssignmentType,
Key1 = ch.Key1,
Key2 = ch.Key2,
LogonID = ch.LogonID,
ProcessDate = ch.ProcessDate,
ProcessTime = ch.ProcessTime,
ProcessUserID = ch.ProcessUserID,
RequestDate = ch.RequestDate,
RequestExport = ch.RequestExport,
RequestNote = ch.RequestNote,
RequestOrigin = Convert.ToChar(ch.RequestOrigin),
RequestProcess = ch.RequestProcess,
RequestStatus = ch.RequestStatus,
RequestTime = ch.RequestTime,
RequestType = Convert.ToChar(ch.RequestType),
ResponseNote = ch.ResponseNote,
TableName = ch.TableName,
TransferDate = ch.TransferDate,
TransferTime = ch.TransferTime,
TransferUserID = ch.TransferUserID,
dispOrigin = (Convert.ToChar(ch.RequestOrigin) == ChangeRequestOrigin.System) ? "System" : (Convert.ToChar(ch.RequestOrigin) == ChangeRequestOrigin.Client) ? "Client" : "Employee",
dispRequestType = (Convert.ToChar(ch.RequestType) == ChangeRequestType.Insert) ? "Insert" : (Convert.ToChar(ch.RequestType) == ChangeRequestType.Alter) ? "Change" : "Delete",
dispStatus = FieldTranslation.GetEnumDescription(typeof(enChangeRequestStatus), ch.RequestStatus ?? 0)
}).OrderByDescending(ch=> ch.RequestID);
return chrwVM;
}