我正在尝试设置路由配置,但出现异常“找到与请求匹配的多个操作:”
当我转到 /api/Devices/{id} 时出现错误
我知道罪魁祸首方法——GetParts。为什么它仍然作为控制器/ID 的可能匹配项触发?如何让它停止,或者只应用 get 方法?
public Devices Get(int id)
{
return Uow.Distribution.Devices.GetById(id);
}
[ActionName("GetParts")]
public IEnumerable<DeviceParts> GetParts(int id)
{
return Uow.Distribution.Devices.GetParts(id);
}
我的路线
routes.MapHttpRoute(
name: ControllerOnly,
routeTemplate: "api/{controller}"
);
routes.MapHttpRoute(
name: ControllerAndId,
routeTemplate: "api/{controller}/{id}",
defaults: null,
constraints: new { id = @"^\d+$" }
);
routes.MapHttpRoute(
name: ControllerAction,
routeTemplate: "api/{controller}/{action}"
);
routes.MapHttpRoute(
name: ControllerActionAndId,
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"^\d+$" }
);
谢谢