C# 绑定到WebAPI的Kendo网格上的分页和筛选
我有一个绑定到WebAPI端点的网格,我想执行服务器端分页和过滤。我正在尝试使用C# 绑定到WebAPI的Kendo网格上的分页和筛选,c#,asp.net-mvc,kendo-ui,kendo-grid,kendo-asp.net-mvc,C#,Asp.net Mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我有一个绑定到WebAPI端点的网格,我想执行服务器端分页和过滤。我正在尝试使用ToDataSourceResult()扩展名。但是,栅格不会渲染结果 我已在控制器中验证响应是否在数据成员上具有正确的项 我的看法是: @{ Layout = "~/Views/Shared/_Layout.cshtml"; } @( Html.Kendo().Grid<CMDB.Entities.Asset>() .Name("AssetGrid") .Columns(
ToDataSourceResult()
扩展名。但是,栅格不会渲染结果
我已在控制器中验证响应是否在数据成员上具有正确的项
我的看法是:
@{
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" })))
))
@{
Layout=“~/Views/Shared/_Layout.cshtml”;
}
@(
Html.Kendo().Grid()
.名称(“资产网格”)
.列(列=>
{
col.Bound(c=>c.AssetTypeInfo.means);
col.Bound(c=>c.AssetSubTypeInfo.means);
col.Bound(c=>c.Name);
col.Bound(c=>c.ManagerInfo.DisplayName);
col.Bound(c=>c.DirectorInfo.DisplayName);
col.Bound(c=>c.BusinessOwnerInfo.DisplayName);
})
.HtmlAttributes(新的{style=“height:300px”})
.Scrollable()
.可过滤()
.Sortable()
.Pageable(p=>p
.页面大小(真)
.刷新(真)
.按钮计数(5))
.DataSource(ds=>ds
.WebApi()
.ServerOperation(真)
.页面大小(20)
.Read(Read=>Read.Url(Url.HttpRouteUrl(“DefaultAPI”),
新的{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;
}
}
[HttpGet]
公共DataSourceResult SearchAssets([ModelBinder(typeof(WebApiDataSourceRequestModelBinder))]DataSourceRequest请求)
{
使用(var ctx=new Data.DBContext())
{
var data=(来自ctx.Query()中的
选择a);
var rr=data.ToDataSourceResult(请求);
返回rr;
}
}
只要我使用实体以外的模型,这似乎可以正常工作。这可能与我的实体中的导航属性有关吗?进一步调查后,这似乎是由我的实体中的导航属性引起的。当我返回DataSourceResult时,它们没有具体化。如果我执行完全相同的步骤,但返回一个具有相同属性(不是虚拟属性)的类,那么它就可以完美地工作。但我觉得有些东西我错过了。我不认为这是对的。剑道格网从不与你的实体一起工作。您需要使用ViewModel或DTO。只要我使用实体以外的模型,这似乎可以正常工作。这可能与我的实体中的导航属性有关吗?进一步调查后,这似乎是由我的实体中的导航属性引起的。当我返回DataSourceResult时,它们没有具体化。如果我执行完全相同的步骤,但返回一个具有相同属性(不是虚拟属性)的类,那么它就可以完美地工作。但我觉得有些东西我错过了。我不认为这是对的。剑道格网从不与你的实体一起工作。您需要使用ViewModel或DTO。