1

I have a controller that looks like this

[HttpGet]
[Route("reporting_values")]
public HttpResponseMessage List()
{
   var queryString = Request.GetQueryNameValuePairs();

// SomeMethod( ** all parameters that exist in the query string ** )

   return Request.CreateResponse(HttpStatusCode.OK);
}

My queryString-variable (key-value pairs) could look something like:
Name - "John Doe"
Age - 31

I would like to pass name and age to SomeMethod if they exist. My query string parameters are optional, thus I would like to use the parameters that were actually passed in the query string in SomeMethod.

i.e. url/reporting_values?Name=John
should result in SomeMethod(Name)

url/reporting_values
should result in SomeMethod()

Is there any way to do this? If not, is there any other way to make efficient use of optional query string parameters?

Nysithea
  • 313
  • 2
  • 14
  • Maybe you can use reflection. Not exactly answers your question but you may get a hint... http://stackoverflow.com/a/10017974/932418 – L.B Oct 27 '16 at 18:00

0 Answers0