【发布时间】:2016-09-15 19:31:29
【问题描述】:
我正在尝试在 Kendo Grid 上实现 OData 以评估性能(我曾使用过实体框架、内联 sql 等)。在我的 api 项目中,我使用的是 OData v4,因为这似乎是 Telerik 使用的。在我的 api 控制器中,我有:
[HttpGet]
[Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
[EnableCors(origins: "http://localhost:50264", headers: "*", methods: "*")]
public IQueryable<vNPISearch> Search(string id)
{
return !String.IsNullOrEmpty(id) ? oandpService.GetPecosQueryable(id) : Enumerable.Empty<vNPISearch>().AsQueryable();
}
我的网格看起来像:
@(Html.Kendo().Grid<vNPISearch>()
.Name("npi-grid")
.Columns(columns =>
{
columns.Template(x => { }).ClientTemplate("#=GetPecosStatus(PecosNPI) #").Width(50);
columns.Bound(x => x.ProviderFirstName).Title("First Name");
columns.Bound(x => x.ProviderLastName).Title("Last Name");
columns.Bound(x => x.ProviderBusinessLocationAddressCity).Title("City");
columns.Bound(x => x.ProviderBusinessLocationAddressState).Title("State");
columns.Bound(x => x.NPI).Title("NPI");
})
.DataSource(dataSource => dataSource
.Custom()
.Schema(sch =>
{
sch.Model(m =>
{
m.Id("NPI");
m.Field(f => f.NPI).Editable(false);
m.Field(f => f.ProviderFirstName).Editable(false);
m.Field(f => f.ProviderLastName).Editable(false);
m.Field(f => f.ProviderBusinessLocationAddressCity).Editable(false);
m.Field(f => f.ProviderBusinessLocationAddressState).Editable(false);
});
})
.Type("odata")
.Transport(transport =>
{
transport.Read(read =>
{
read.Url("http://localhost:58242/api/PecosSearch/Search?id=" + Model.SearchTerm);
read.DataType("json");
});
})
.PageSize(20)
.ServerPaging(true)
.ServerSorting(true)
.ServerFiltering(true)
)
.Scrollable(scr => scr.Height("auto"))
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
)
当我进入搜索页面时,该页面有一个搜索文本框和网格。当我对它运行查询时,我得到“不支持查询参数'$count'。”
如果我在 Postman 中删除 $count,API 就可以工作。
知道发生了什么吗?
谢谢,
AJ
【问题讨论】:
-
首先,尝试将 .Type("odata") 更改为 .Type("odata-v4")。 github.com/telerik/ui-for-aspnet-mvc-examples/blob/master/grid/…
-
谢谢,但我试过了 :(
-
我怀疑是 api 方面。返回的是什么DataServiceVersion?
-
我其实不确定。我安装了这个插件 (chrome.google.com/webstore/detail/http-headers/…) 但它没有在标题中显示 DataServiceVersion...
-
你的控制器是继承自 ODataController 还是 ApiController?
标签: c# kendo-ui telerik kendo-grid kendo-asp.net-mvc