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?