我正在尝试设置路由配置,并且遇到异常“找到了与请求匹配的多个操作:”
当我转到/ 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+$" }
);
由于