相关疑难解决方法(0)

ASP.NET Web API中具有多个GET方法的单个控制器

在Web API中,我有一类类似的结构:

public class SomeController : ApiController
{
    [WebGet(UriTemplate = "{itemSource}/Items")]
    public SomeValue GetItems(CustomParam parameter) { ... }

    [WebGet(UriTemplate = "{itemSource}/Items/{parent}")]
    public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }
}
Run Code Online (Sandbox Code Playgroud)

由于我们可以映射单个方法,因此在正确的位置获得正确的请求非常简单.对于只有一个GET方法但也有Object参数的类似类,我成功使用了IActionValueBinder.但是,在上述情况下,我收到以下错误:

Multiple actions were found that match the request: 

SomeValue GetItems(CustomParam parameter) on type SomeType

SomeValue GetChildItems(CustomParam parameter, SomeObject parent) on type SomeType
Run Code Online (Sandbox Code Playgroud)

我试图通过重写ExecuteAsync方法来解决这个问题ApiController但到目前为止没有运气.关于这个问题的任何建议?

编辑:我忘了提到现在我试图在ASP.NET Web API上移动此代码,它具有不同的路由方法.问题是,如何使代码在ASP.NET Web API上运行?

c# asp.net-web-api

156
推荐指数
9
解决办法
20万
查看次数

标签 统计

asp.net-web-api ×1

c# ×1