0

I am using DataTable for displaying the list of product, the product include picture, when i return json file from my controller it gives me error

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property

I configure my web.config as

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

if i return json without picture is display properly, is there any solution to return a list of picture using json.

and my controller is

public JsonResult CustomServerSideSearchAction(DataTableAjaxPostModel model)
    {
        int filteredResultsCount;
        int totalResultsCount;
        var res = CustomSearchFunc(model, out filteredResultsCount, out totalResultsCount);

        var result = new List<ProductGrid>(res.Count);
        result.AddRange(res.Select(s => new ProductGrid
        {
            ProductImage = s.ProductImage,
            ProductId = s.ProductId,
            ProductName = s.ProductName,
            ProdutCode = s.ProdutCode,
            ProductPrice = s.ProductPrice,
            ProductQuantity = s.ProductQuantity,
            HeadOfficeId = s.HeadOfficeId,
            BranchOfficeId = s.BranchOfficeId
        }));

        if (totalResultsCount < model.length)
            totalResultsCount = model.length;

        return Json(new
        {
            model.draw,
            recordsTotal = totalResultsCount,
            recordsFiltered = filteredResultsCount,
            data = result
        }, JsonRequestBehavior.AllowGet);
    }

how can i resolve this problem???? thanks....

MD MASUM
  • 49
  • 11
  • Take a look at:https://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config – Prashant Pimpale Dec 31 '18 at 05:14
  • I did that but same error, i set max length in web.config and i also set it in my controller `JavaScriptSerializer jss = new JavaScriptSerializer(); jss.MaxJsonLength = Int32.MaxValue;` – MD MASUM Dec 31 '18 at 05:26

0 Answers0