Search code examples
asp.net-mvcasp.net-mvc-4asp.net-web-api

How to get GET parameters with ASP.NET MVC ApiController


I feel a bit absurd asking this but I can't find a way to get parameters for a get request at /api/foo?sort=name for instance.

In the ApiController class, I gave a public string Get(). Putting Get(string sort) makes /api/foo a bad request. Request instance in the ApiController is of type System.Net.Http.HttpRequestMessage. It doesn't have a QueryString or Parameters property or anything.


Solution

  • You could just use

    HttpContext.Current.Request.QueryString