我使用vs2017 结合Kendo.for.AspNet.Core插件实现列表页面,但是一直绑定数据不成功,提示:Failed to load resource: the server responded with a status of 400 (Bad Request)
List页面代码:
@using Kendo.Mvc.UI;
<div>
@(Html.Kendo().Grid<GridModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.name).Width(150);
columns.Bound(p => p.yearly).Width(150);
columns.Bound(p => p.wordtext).Width(150);
columns.Bound(p => p.ModelId).Width(130);
columns.Command(command => command.Destroy()).Width(160);
})
.ToolBar(toolbar =>
{
toolbar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Groupable()
.Filterable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Read("List_Read", "KendoGrid")
)
)
</div>
控制器:
public class KendoGridController : Controller
{
public ActionResult List()
{
return View();
}
[HttpPost]
public ActionResult List_Read([DataSourceRequest] DataSourceRequest request)
{
IEnumerable<GridModel> Read = GetAll();
return Json(Read.ToDataSourceResult(request));
}
public IList<GridModel> GetAll()
{
var result = Enumerable.Range(0, 50).Select(i => new GridModel
{
name = "test",
yearly = DateTime.Now.Year,
wordtext = "测试",
ModelId = i
}).ToList();
return result;
}
}
Model:
public class GridModel
{
public string name { get; set; }
public int yearly { get; set; }
public string wordtext { get; set; }
public int ModelId { get; set; }
}