This is a migrated thread and some comments may be shown as answers.

Grid doesn't work MVC 4 RC

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
peter
Top achievements
Rank 1
peter asked on 20 Jun 2012, 04:23 AM
Hi,
 I tried to move from MVC 3  to mvc 4. unfortunately, the following code is working properly on mvc 3, but on mvc4 rc shows "No records to display". how to avoid this issue?

@(Html.Kendo().Grid<Object>()    
    .Name("GridTest") 
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Test_Read", "Home"))
     )
     .Resizable(resize => resize.Columns(true))
     .Reorderable(reorder => reorder.Columns(true))

Thanks,

peter

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 14 Aug 2012, 08:12 AM
I had the same problem.

Here is my solution:

1. disable proxy generation for the read function only
     
context.Configuration.ProxyCreationEnabled = false;

2. configure JsonFormatter like this (global.asax; application_start)
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

3. set JsonRequestBehavior for the jsonresult in the read function to AllowGet
return Json(result, JsonRequestBehavior.AllowGet);

ends up like this:
public JsonResult Read([DataSourceRequest]DataSourceRequest request)
{
    var context = new SampleContext();
    context.Configuration.ProxyCreationEnabled = false;
    var data = context.Data;
    DataSourceResult result = data.ToDataSourceResult(request);
    return Json(result, JsonRequestBehavior.AllowGet);
}
Tags
Grid
Asked by
peter
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or