MVC route with id and sub-action

Posted by Dan Revell on Stack Overflow See other posts from Stack Overflow or by Dan Revell
Published on 2012-10-04T09:35:27Z Indexed on 2012/10/04 9:37 UTC
Read the original article Hit count: 201

Filed under:
|

I can't figure out what I need to do with MVC routing to make this work

Here's my one route:

routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "{controller}/{id}/{action}",
    defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional }
);

The request /Shipments/ works great.

The request /Shipments/3/Packages works great.

The request /Shipments/3 however fails with the error:

Multiple actions were found that match the request: System.Linq.IQueryable`1[Api.Controllers.RequisitionsController+PackageRequisitionWithTracking] GetPackageRequisitions(Int32) on type Api.Controllers.RequisitionsController Api.Models.ShipmentRequisition GetShipmentRequisitions(Int32) on type Api.Controllers.RequisitionsController

It can't seem to differentiate between:

public ShipmentRequisition GetShipmentRequisitions(int id)

and

[ActionName("Packages")]
public IQueryable<PackageRequisitionWithTracking> GetPackageRequisitions(int id)

I would have thought the lack of action name on the get shipment by id would allow that route to work.

© Stack Overflow or respective owner

Related posts about routes

Related posts about asp.net-web-api