Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASPNet.Core 1.0 RTM Kendo Grid not displaying data

It looks like the new internal build (2016.2.630) for ASPNet Kendo MVC does not work with the Kendo Grid. Or at least not with returning Json from a Read action in the grid.

@(Html.Kendo().Grid<EmployeeModel>()
.Name("grid")
.Columns(columns =>
{
    columns.Bound(p => p.EmployeeID).Visible(false);
    columns.Bound(p => p.Name);
    columns.Bound(p => p.Salary);
})
.Pageable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .Read(read => read.Action("Employees_Read", "Home"))
 )
 .Deferred()

)

This is the Read Action in the controller:

public ActionResult Employees_Read([DataSourceRequest] DataSourceRequest request)
    {
        List<EmployeeModel> employees = new List<EmployeeModel>();
        employees.Add(new EmployeeModel() { EmployeeID = 1, Name = "Peter Pan", Salary = new decimal(23340.35) });
        employees.Add(new EmployeeModel() { EmployeeID = 2, Name = "Little John", Salary = new decimal(25320.45)});
        employees.Add(new EmployeeModel() { EmployeeID = 3, Name = "Tinkerbell", Salary = new decimal(21520.45) });
        employees.Add(new EmployeeModel() { EmployeeID = 4, Name = "Captain Hook", Salary = new decimal(45320.45) });
        var checkResult = employees.ToDataSourceResult(request);
        return Json(checkResult);
    }

With a simple Model:

public class EmployeeModel
{
    public int EmployeeID { get; set; }
    public string Name { get; set; }
    public decimal Salary { get; set; }
}

The grid is not showing data from the Read Action. This is only since the release of AspNet.Core 1.0 Core and applying the latest release 2016.2.630 of Kendo.MVC.

Is there any workaround for this?

like image 765
MerlinNZ Avatar asked Dec 15 '22 05:12

MerlinNZ


1 Answers

This is probably because MS Changes Json serialization in the RTM bits to always be pascalCase. You can probably mitigate this by adding a json option like this:

change

services.AddMvc();

to

services
        .AddMvc()
        .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

until Telerik updates all the JavaScripts

From this: https://github.com/telerik/kendo-ui-core/issues/1856

like image 122
neodim Avatar answered Jan 01 '23 12:01

neodim