UPDATE
My initial assumption was that the cause was a problem with additional parameters. This seems wrong. Instead, the problem appears to be related to several action methods when one of these methods contains valid value types (for example, int?) For some parameters.
I am using Visual Studio 2012 RC and getting started with the Web API. I encountered a problem and get the error message "There are no actions on the Bars controller that match the request."
I have a Bars controller. It has a Get () method that accepts optional parameters.
public IEnumerable<string> Get(string h, string w = "defaultWorld", int? z=null) { if (z != 0) return new string[] { h, w, "this is z: " + z.ToString() }; else return new string[] { h, w }; }
So, I am checking it with the following urls
- / api / bars? H = hi
- / Api / bars h = hello &? W = world
- / Api / h bar = hello &? W = peace & r = 15
And it works for all three.
Then I go to add another Get () method, this time with one id parameter
public string Get(int id) { return "value"; }
I am checking the URL again. Is it time / api / bars? H = hello & w = world and api / bars? H = hello fail. Error message "No actions were found on the control panel of the controller that match the request.
For some reason, these two methods do not mix well with each other. If I remove Get(int id)
, it will work. Should I change int? z to string z, then it works (but then it requires transforming objects inside my action method!).
Why does the web API do this? Is this a bug or design?
Many thanks.