ASPNet.Core 1.0 RTM Kendo网格不显示数据 [英] ASPNet.Core 1.0 RTM Kendo Grid not displaying data

查看:80
本文介绍了ASPNet.Core 1.0 RTM Kendo网格不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎ASPNet Kendo MVC的新内部版本(2016.2.630)无法与Kendo Grid一起使用.或者至少不是通过从网格中的读取"操作返回Json.

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);
    }

使用简单的模型:

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

网格未显示读取操作"中的数据. 这仅是因为发布了AspNet.Core 1.0 Core并应用了Kendo.MVC的最新版本2016.2.630.

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.

有什么解决方法吗?

推荐答案

这可能是因为MS将RTM位中的Json序列化更改为始终为pascalCase. 您可以通过添加如下json选项来缓解这种情况:

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:

更改

services.AddMvc();

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

直到Telerik更新所有JavaScript

until Telerik updates all the JavaScripts

来自此: https://github.com/telerik/kendo-ui-core/issues/1856

这篇关于ASPNet.Core 1.0 RTM Kendo网格不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆