看起来ASPNet Kendo MVC的新内部版本(2016.2.630)无法与Kendo Grid一起使用。或者至少不是从网格中的Read动作返回Json。
@(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()
)
这是控制器中的Read Action:
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发布以及应用最新版本2016.2.630的Kendo.MVC之后。
有没有解决方法呢?
答案 0 :(得分:12)
这可能是因为MS将RTM位中的Json序列化改为始终为pascalCase。 你可以通过添加像这样的json选项来缓解这种情况:
变化
services.AddMvc();
到
services
.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
直到Telerik更新所有JavaScripts