How to get GET parameters with ASP.NET MVC ApiController

The ApiController is designed to work without the HttpContext object (making it portable, and allowing it to be hosted outside of IIS).

You can still access the query string parameters, but it is done through the following property:

Request.GetQueryNameValuePairs()

Here’s an example loop through all the values:

foreach (var parameter in Request.GetQueryNameValuePairs())
{
     var key = parameter.Key;
     var value = parameter.Value;
}

Leave a Comment