gpt4 book ai didi

c# - 将 OData 过滤器与 C# MVC 4 Web Api 和主干一起使用

转载 作者:太空狗 更新时间:2023-10-30 01:24:04 24 4
gpt4 key购买 nike

这是我第一次尝试很棒的 Web Api 和 Backbone。到目前为止,一切似乎都是天作之合。但是我似乎无法使用 OData 过滤器返回相关数据。例如,我将以下内容作为操作方法:

    //GET /api/posts/
public IQueryable<KiaFamilyPost> Get()
{
return _db.Posts
.Include("Badge")
.Include("Entry")
.AsQueryable();
}

现在我想过滤上面的帖子,并按降序返回。根据我的理解,我可以执行以下操作 "http://[MySite]/api/posts?$filter=id eq 2&$orderby=DatePost desc"。我正在尝试执行以下操作但无济于事:

        APP.posts_collection.fetch({data: {
entryId: APP.entry.get('Id'),
$order: 'Id desc'
}});

Backbone 对 Controller "http://[MySite]/api/posts?entryId=1&%24order=Id+desc" 进行以下调用。有人能让它正常工作吗?

谢谢

泰隆

最佳答案

我试验了 Addy Osmani 的一个名为 backbone.paginator 的插件.如果您正在使用像 MVC 4 这样的 Web Api,我相信这将非常适合。您所做的就是使用分页器提供的一些参数扩展您的集合。例如。

    perPageAttribute: '$top',

skipAttribute: '$skip',

orderAttribute: 'orderBy',

customAttribute1: '$inlinecount',

queryAttribute: '$filter',

formatAttribute: '$format',

customAttribute2: '$callback',`

关于c# - 将 OData 过滤器与 C# MVC 4 Web Api 和主干一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10365189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com