Accessing the query string in ASP.Net Web Api?

asp.net-web-api, query-string, routes

Solution

The query string key name should match the parameter name of the action:

/api/values?queryString=f

public IEnumerable<string> Get(string queryString)
    {
        return new string[] { "value3", "value4" };
    }

Problem

I'm using the default template generated by Asp.net Web Api. I'm working with the Get() part: ``` // GET api/values public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } ``` For some reason I thought the only thing you had to do to access to query string was just to create an input string variable. So I created one more function (the only change I made) to the default controller generated: ``` public IEnumerable<string> Get(string queryString) { return new string[] { "value3", "value4" }; } ``` I put a breakpoint in both methods but even if I add a query string it always goes to the function with no parameters. So if I go to `http://mybaseurl/api/values?foo=f` it still is going to Get() instead of Get(string queryString). Does it not work the way I thought? I know I can access the query string in the Get() function using `Request.RequestUri.ParseQueryString();` but I prefer to have it separated like this if possible.

Original source