I am trying to send json from my MVC controller, its exceptions exceptions, errors during serialization or deserialization using JSON JavaScriptSerializer. The string is longer than the value specified for the maxJsonLength property.
I googled and added the maximum length in my configuration, also redefined my json method, nothing worked.
Here is my web configuration 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(); }
I get an exception in the next 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 the maximum json length is about 200000, how to increase the size, nothing happens. any help please?
Thanks in advance.