【发布时间】:2013-06-15 15:57:10
【问题描述】:
我的控制器的路由和操作选择有问题。 我的路由看起来像:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}/{action}",
defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional });
我的控制器看起来像:
[HttpGet]
public Customers GetCustomers()
{
}
[HttpGet]
public Customer GetCustomerDetail(int id)
{
}
[ActionName("orders")]
[HttpGet]
public Orders GetCustomerOrders(int id)
{
}
我可以打电话给http://localhost/customers,也可以打电话给http://localhost/customers/1/orders。
但是当我尝试调用 http://localhost/customers/1 时,我会收到错误消息“找到与请求匹配的多个操作:”(与 GetCustomerDetail 和 GetCustomerOrders 匹配)。
知道如何解决这个问题吗?
谢谢
【问题讨论】:
-
明确调用您的操作,
http://localhost/customers/GetCustomerDetail/1 -
是的,好的,但这不是我想要达到的目标 ;-) 而且这根本不合逻辑。它应该是'localhost/customers/1'。
标签: c# asp.net asp.net-web-api asp.net-web-api-routing