【问题标题】:Kendo UI Grid using OData returns "The query parameter '$count' is not supported."使用 OData 的 Kendo UI Grid 返回“不支持查询参数 '$count'。”
【发布时间】: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

【问题讨论】:

标签: c# kendo-ui telerik kendo-grid kendo-asp.net-mvc


【解决方案1】:

我认为您必须使用 ToDataSourceResult 扩展方法从服务器返回此值。

    using using Kendo.Mvc.Extensions;

    public ActionResult Search(string id, [DataSourceRequest] DataSourceRequest request){
        return !String.IsNullOrEmpty(id) ? oandpService.GetPecosQueryable(id).ToDataSourceResult(request) : Enumerable.Empty<vNPISearch>().AsQueryable().ToDataSourceResult(request);
    }

编辑:将集合更改为 ActionResult 将允许数据通过。

【讨论】:

  • 感谢您的回复。当我这样做时,我收到错误“无法将类型 DataSourceResult 隐式转换为 IQueryable.
  • 将结果类型改为ActionResult是否有效。
  • 这只会给出错误“无法将 DataSourceResult 隐式转换为 ActionResult。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-15
相关资源
最近更新 更多