Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.


What I have tried:

Controller

public JsonResult GetPeriodById(int PeriodId)
        {
            Tbl_Periods model;
            model = db.Tbl_Periods.Where(s => s.Period_Id == PeriodId).SingleOrDefault();

            string value = string.Empty;
            value = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            return Json(value, JsonRequestBehavior.AllowGet);
        }




Javascript
function EditStudentRecord(PeriodId) {
       var url = config.serverPath + "Home/GetPeriodById?PeriodId=" + PeriodId;
       $("#ModalTitle").html("Update Period");
       $("#MyModal").modal();
       $.ajax({
           type: "GET",
           url: url,
           success: function (data) {
               var obj = JSON.parse(data);
               $("#pId").val(obj.Period_Id);
               $("#stDate").val(obj.Start_Date);
               $("#endDate").val(obj.End_Date);
               $("#projectID").val(obj.project_Id);
              //$("#DropDwn option:selected").text(obj.tblDepartment.DepartmentName);
               //$("#DropDwn option:selected").val(obj.DepartmentId);
           }
       })
   }
Posted
Updated 17-Jul-19 2:06am
Comments
F-ES Sitecore 17-Jul-19 4:16am    
This is configuration problem, not a code problem. Google the error message and you'll see what you need to do to fix this. You should always do basic research such as using google before posting a question.

1 solution

First google result has your answer, Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property – Mayur's Blog[^].

I suggest you do a little research yourself next time. It will be much faster.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900