Reputation: 8372
I have a method defined in ApiController. When the method is defined like this :
public IEnumerable<QuestionResponse> Get()
Everything is fine. However I want to pass a parameter to that method but when I define that method as
public IEnumerable<QuestionResponse> Get(int parid)
The response is a 405 "The requested resource does not support http method 'GET'".
When there's no parameter defined for the method then both of these urls are routed to the method :
/api/questionresponse/224809
/api/questionresponse
But when I define an argument to that method both of those urls result in a 405 .
Help ?
FWIW
Upvotes: 2
Views: 740
Reputation: 9764
If you check the route you can see the default template makes use of parameter {id}
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
So you need to change the controller signature to
public IEnumerable<QuestionResponse> Get(int id)
Or write a Custom route to support parameter parid
Upvotes: 3