Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用OData返回的剑道UI网格;查询参数'$计数';不支持;_C#_Kendo Ui_Telerik_Kendo Grid_Kendo Asp.net Mvc - Fatal编程技术网

C# 使用OData返回的剑道UI网格;查询参数'$计数';不支持;

C# 使用OData返回的剑道UI网格;查询参数'$计数';不支持;,c#,kendo-ui,telerik,kendo-grid,kendo-asp.net-mvc,C#,Kendo Ui,Telerik,Kendo Grid,Kendo Asp.net Mvc,我试图在剑道网格上实现OData以评估性能(我曾经使用实体框架、内联sql等)。在我的api项目中,我使用的是ODataV4,因为Telerik似乎就是用它工作的。在我的api控制器中,我有: [HttpGet] [Queryable(AllowedQueryOptions = AllowedQueryOptions.All)] [EnableCors(origins: "http://localhost:50264", headers: "*", methods: "*")] public I

我试图在剑道网格上实现OData以评估性能(我曾经使用实体框架、内联sql等)。在我的api项目中,我使用的是ODataV4,因为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();
}
[HttpGet]
[可查询(AllowedQueryOptions=AllowedQueryOptions.All)]
[使能CORS(来源:http://localhost:50264,标题:“*”,方法:“*”]
公共IQueryable搜索(字符串id)
{
return!String.IsNullOrEmpty(id)?oandpService.GetPecosQueryable(id):Enumerable.Empty().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))
)
@(Html.Kendo().Grid())
.名称(“npi网格”)
.列(列=>
{
columns.Template(x=>{}).ClientTemplate(“#=GetPecosStatus(PecosNPI)#”)。宽度(50);
columns.Bound(x=>x.ProviderFirstName).Title(“名字”);
columns.Bound(x=>x.ProviderLastName).Title(“姓氏”);
columns.Bound(x=>x.ProviderBusinessLocationAddressCity).Title(“城市”);
columns.Bound(x=>x.ProviderBusinessLocationAddressState).Title(“状态”);
columns.Bound(x=>x.NPI).Title(“NPI”);
})
.DataSource(DataSource=>DataSource
.Custom()
.Schema(sch=>
{
sch.模型(m=>
{
m、 Id(“NPI”);
m、 字段(f=>f.NPI)。可编辑(false);
m、 字段(f=>f.ProviderFirstName)。可编辑(false);
m、 字段(f=>f.ProviderLastName)。可编辑(false);
m、 字段(f=>f.ProviderBusinessLocationAddressCity)。可编辑(false);
m、 字段(f=>f.ProviderBusinessLocationAddressState)。可编辑(false);
});
})
.类型(“odata”)
.运输(运输=>
{
transport.Read(Read=>
{
read.Url(“http://localhost:58242/api/PecosSearch/Search?id=“+Model.SearchTerm);
read.DataType(“json”);
});
})
.页面大小(20)
.ServerPaging(真)
.ServerSorting(true)
.ServerFiltering(true)
)
.可滚动(scr=>scr.高度(“自动”))
.Sortable()
.Pageable(Pageable=>Pageable
.刷新(真)
.页面大小(真)
.按钮计数(5))
)
当我进入搜索页面时,它有一个搜索文本框和网格。当我对它运行查询时,我得到“不支持查询参数“$count”

如果我在Postman中删除$count,则API可以工作

知道发生了什么吗

谢谢


AJ

我认为您必须使用
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);
    }
使用Kendo.Mvc.Extensions;
公共操作结果搜索(字符串id,[DataSourceRequest]DataSourceRequest请求){
return!String.IsNullOrEmpty(id)?oandpService.GetPecosQueryable(id).ToDataSourceResult(请求):Enumerable.Empty().AsQueryable().ToDataSourceResult(请求);
}

编辑:将集合更改为ActionResult将允许数据传递。

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

    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);
    }
使用Kendo.Mvc.Extensions;
公共操作结果搜索(字符串id,[DataSourceRequest]DataSourceRequest请求){
return!String.IsNullOrEmpty(id)?oandpService.GetPecosQueryable(id).ToDataSourceResult(请求):Enumerable.Empty().AsQueryable().ToDataSourceResult(请求);
}

编辑:将集合更改为ActionResult将允许数据传递。

首先,尝试将.Type(“odata”)更改为.Type(“odata-v4”)。谢谢,但我尝试过:(我怀疑api方面。它返回了什么?我实际上不确定。我安装了这个插件(),但它在标题中没有显示DataServiceVersion…您的控制器是从ODataController还是ApicController继承的?首先,尝试将.Type(“odata”)更改为.Type(“odata-v4”)。谢谢,但我尝试过:(我怀疑api方面。它返回了什么?实际上我不确定。我安装了这个插件(),但它在标题中没有显示DataServiceVersion…您的控制器是从ODataController还是ApicController继承的?感谢您的响应。当我这样做时,我得到了错误。)无法将类型DataSourceResult隐式转换为IQueryable。如果将结果类型更改为ActionResult,是否有效。这只会导致错误“无法将DataSourceResult隐式转换为ActionResult。感谢您的响应。当我这样做时,我会收到错误”无法将类型DataSourceResult隐式转换为IQueryable。如果将结果类型更改为ActionResult,是否有效。这只会导致错误“无法将DataSourceResult隐式转换为ActionResult”。