【问题标题】:pagination ruins other actions webapi分页破坏了其他操作 webapi
【发布时间】:2018-01-04 05:17:06
【问题描述】:

我正在尝试为 webapi 中的资源实现分页,但它破坏了返回 singleById 资源的其他操作。

所以有两个函数可以在我的 api 中获取对象(一个是另一个质量,但是是分页的),如下所示:

public HttpResponseMessage Get(int page,string type="mm");
public HttpResponseMessage Get(int id);

type 选项是半搜索,类似于可选过滤器。

我知道它有冲突我将它设为字符串 id 但它不起作用,我想了一种方法单独路由每个操作或重命名它们但它不起作用因为默认路由就像 api/{controller}/{id} 并且没有t 在我不喜欢生成 api/{controller}/post/ 旁边包含操作名称。

【问题讨论】:

标签: asp.net-web-api pagination


【解决方案1】:

我决定使用Attribute Routing

[Route("specefiedController/{id}/single")]

拥有getById 操作并让其他操作保持原样

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 2020-02-27
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多