在网页API我有一类结构相似的:处理ASP.NET Web API多个GET方法单控制器
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) { ... }
}
因为我们可以映射单独的方法,这是非常简单的,以获得正确的请求,在正确的地方。对于只有一个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
我试图通过覆盖的ApiController
的ExecuteAsync
方法,但没有运气迄今为止解决这个问题。有关此问题的任何建议?
编辑:我忘了提,我现在想继续前进的ASP.NET Web API的代码具有不同的方法来路由。问题是,我如何使代码在ASP.NET Web API上工作?
您是否仍然得到了{}父作为RouteParameter.Optional? – 2012-02-29 19:10:49
是的,我做到了。也许我错误地使用了IActionValueBinder,因为对于像int id这样的类型(如在演示中),它确实工作正常。 – 2012-02-29 19:39:16
对不起,我应该更清楚。我会认为将它作为可选项意味着它与项目路线以及子项目路线相匹配,这将解释您所看到的错误消息。 – 2012-02-29 19:48:00