c# - Multiple actions were found that match the request in Web Api -
i keep getting error when try have 2 "get" methods
multiple actions found match request: webapi
i been looking around @ other similar questions on stack don't it.
i have 2 different names , using "httpget" attribute
[httpget] public httpresponsemessage summary(myvm vm) { return null; } [httpget] public httpresponsemessage fulldetails() { return null; }
your route map this:
routes.maphttproute( name: "api default", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional });
but in order have multiple actions same http method need provide webapi more information via route so:
routes.maphttproute( name: "api default", routetemplate: "api/{controller}/{action}/{id}", defaults: new { id = routeparameter.optional });
notice routetemplate includes action. lots more info here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api
update:
alright, think understand after here take @ this:
perhaps don't need action url parameter , should describe contents after in way. since saying methods returning data same entity let parameters describing you.
for example 2 methods turned into:
public httpresponsemessage get() { return null; } public httpresponsemessage get(myvm vm) { return null; }
what kind of data passing in myvm object? if able pass variables through uri, suggest going route. otherwise, you'll need send object in body of request , isn't http of when doing (it works though, use [frombody] infront of myvm).
hopefully illustrates can have multiple methods in single controller without using action name or [httpget] attribute.
Comments
Post a Comment