我有一个绑定到WebAPI端点的网格,我想执行服务器端分页和过滤。我正在尝试使用ToDataSourceResult()
扩展程序。但是,网格不会显示结果。
我已在控制器中验证了响应确实在Data成员上有正确的项目。
我的观点:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@(
Html.Kendo().Grid<CMDB.Entities.Asset>()
.Name("AssetGrid")
.Columns(col =>
{
col.Bound(c => c.AssetTypeInfo.Meaning);
col.Bound(c => c.AssetSubTypeInfo.Meaning);
col.Bound(c => c.Name);
col.Bound(c => c.ManagerInfo.DisplayName);
col.Bound(c => c.DirectorInfo.DisplayName);
col.Bound(c => c.BusinessOwnerInfo.DisplayName);
})
.HtmlAttributes(new { style = "height: 300px" })
.Scrollable()
.Filterable()
.Sortable()
.Pageable(p => p
.PageSizes(true)
.Refresh(true)
.ButtonCount(5))
.DataSource(ds => ds
.WebApi()
.ServerOperation(true)
.PageSize(20)
.Read(read => read.Url(Url.HttpRouteUrl("DefaultAPI",
new { controller = "Values", action = "SearchAssets" })))
))
我的控制器操作:
[HttpGet]
public DataSourceResult SearchAssets([ModelBinder(typeof(WebApiDataSourceRequestModelBinder))] DataSourceRequest request)
{
using (var ctx = new Data.DBContext())
{
var data = (from a in ctx.Query<Entities.Asset>()
select a);
var rr = data.ToDataSourceResult(request);
return rr;
}
}