Reputation: 79
I am Binding data to Kendo grid using Ienumerable not with Json Data .
Am Getting this Error : Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Even after tried with setting below maxjsonlength in web.config
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647" />
</webServices>
</scripting>
Here is my kendo Grid
@model IEnumerable<AssetTrackingSystem.Model.SampleDetailsSummary>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns=>
{
columns.Bound(p => p.JobNumber).Title("Job Number").Width("125px");
columns.Bound(p => p.SampleNumber).Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("SampleDetails", "JobDetails", new { AssetId = "#=AssetId#" }) + "'>#=SampleNumber#</a>").Title("Sample Number").Width("125px");
columns.Bound(p => p.SampleType).Title("Sample Type").Width("125px");
columns.Bound(p => p.ServiceVendor).Title("Service Vendor").Width("125px");
columns.Bound(p => p.BarCode).Title("Barcode").Width("125px");
columns.Bound(p => p.LocationName).Title("Current Location").Width("125px");
columns.Bound(p => p.GPS).Title("GPS").Width("125px");
}).Pageable().Sortable().Scrollable(scr => scr.Height(scroolheight)).Filterable().Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5)).DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.ServerOperation(false)
.Model(model => model.Id(p => p.AssetId))
)
Here is my controller action Method
public ActionResult CompanyAssets()
{
Guid CompanyId = new Guid(Request.Params["CompanyId"].ToString());
int GPSOnly = int.Parse(Request.Params["Gps"]);
//bool GPSOnly = GPSOnly1.Equals("1") ? true : false;
JobDetailsRepository rep = new JobDetailsRepository(Session["Connectionstring"].ToString());
// IList<AssetDetails> assetinfo = rep.GetAssetsByCompanyId(CompanyId);
IList<SampleDetailsSummary> assetinfo = rep.GetAllSamplesByCompanyId(CompanyId, GPSOnly);
CompanyRepository cmprep = new CompanyRepository(Session["Connectionstring"].ToString());
// IList<CompanyInfoSummary> s = cmprep.GetLocationsByCompanyId(CompanyId);
var company = cmprep.GetCompany(CompanyId);
ViewBag.companyName = company.CompanyName;
var model = assetinfo;
return View(model);
}
Can any one please help me through this am trying to fix these spending 24 hours
Upvotes: 0
Views: 737
Reputation: 13949
Your issue might be that you're binding your grid to an object that has a circular reference..
for example..
public class Employee
{
public Company Company {get;set}
}
public class Company
{
public Employee Owner { get; set}
}
the serializer will get stuck in an infinite loop here since employee has a company and company has an employee.
another issue could be the size of your IEnumerable<AssetTrackingSystem.Model.SampleDetailsSummary>
is so large that is just exceeds the max length allowed.
the best way to avoid this with Kendo is to create View Models and bind your grid to those instead of actual database entities.
If SampleDetailsSummary
only had the fields you're displaying in the grid and you can't make it any smaller by eliminating extra properties, then you should look into using the actual ajax functionality and doing paging server side.
Upvotes: 2