2

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

1
  • Try changing your parameter name from parid to id, it should work Commented Sep 1, 2015 at 5:33

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response, I appreciate it. I can see the logic of your suggestion but when I rename the argument I still get the same result.. SORRY CANCEL THAT ... I didn't test it properly. Just testing again.
thank you very much that is indeed the answer. I had looked at the WebApiConfig.cs but I was thinking the 'id' was a placeholder rather than an actual name mapping ...not sure why I would think that ! Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.