I am trying to send json from my MVC controller, its throwing exception, Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
I googled and added the max length in my config, also overridden my json method, nothing working out.
Here is my web config and my method, its throwing exception. in appsetting
<add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647">
</jsonSerialization>
</scripting>
</system.web.extensions>
over ridden method
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
};
}
my method
public JsonResult GetAttributeControls()
{
List<SelectListItem> attrControls;
using (var context = new Context())
{
attrControls = context.AttributeControls.ToList().
Select(ac => new SelectListItem { Text = ac.Name, Value = ac.AttributeControlId.ToString() }).ToList();
}
//var jsonResult = Json(attrControls, JsonRequestBehavior.AllowGet);
//jsonResult.MaxJsonLength = int.MaxValue;
//return jsonResult;
return Json(attrControls,JsonRequestBehavior.AllowGet);
}
I am getting exception in the below line this is my load.chtml file
<script type="text/javascript">
var InitialRowData = '@Html.Raw(Json.Encode(Model))';
var isLayoutEditable = false;
var occupied = '@Model.occupied';
var notoccupied = '@Model.notoccupied';
var blocked = '@Model.blocked';
</script>
@Html.Raw(Json.Encode(Model))';
there json maximum length is around 200000, how to increase the size, nothing working out. any help please?
Thanks in advance.