c# - Multiple actions were found that match the request when using actions in Route config -
c# - Multiple actions were found that match the request when using actions in Route config -
i'm building api using web api 2.2
i have restful part of working need 1 non-restful controller:
public class premisescontroller : apicontroller { private premiseservice _service; public premisescontroller() { _service = new premiseservice(); } [httpget] public ihttpactionresult premise(string id) { id = id.replace(" ", string.empty).toupper(); list<premise> premises = _service.getpremisesforpostcode(id); homecoming ok(premises); } [httpget] public ihttpactionresult building(string id) { double premise = convert.todouble(id); building building = _service.getbuildingsforpremise(premise); homecoming ok(building); } } the routing config follows:
config.maphttpattributeroutes(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); config.routes.maphttproute( name: "actionapi", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional } ); im getting error can't distinguish between 2 methods when initiate action:
multiple actions found match request
so question need specify route attribute on top of each method , if yes, why? doesn't sec route (actionapi) deals situation?
edit:
i tested you're code , works way is... maybe unclear.
/api/premises/premise/8 --> take first action /api/premises/building/8 --> take sec action /api/premises/8 --> cause error because routing go first rule api/{controller}/{id} request, can't distinguish of actions want because both match first route: (api/premises/{id}) c# asp.net-web-api2 asp.net-web-api-routing asp.net-mvc-5.2
Comments
Post a Comment