Actions and QueryString parameters in Web API
asp.net-web-api, asp.net-web-api-routing, query-string
Solution
In the controller action, just include `DateTime dateOfLog` as a method parameter and continue to use the query string as it will get mapped just fine, Web API will use the correct method overload if it finds it.
Problem
I want to have my generic route determine if a query string was passed in the Url like this ``` http://localhost/query/DailyLogs/1?dateOfLog='1/13/2013' ``` Here is my current Route definition: ``` routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "query/{controller}/{id}", defaults: new { id = RouteParameter.Optional} ); ``` I have read some answers that say to add the dateOfLog value as an optional action on the Route defintion: ``` routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "query/{controller}/{id}/{dateOfLog}", defaults: new { id = RouteParameter.Optional, dateOfLog = RouteParameter.Optional } ); ``` This does not seem to work, maybe I am doing something wrong, I am not sure. This is how I am currently handling the problem, but I would like to use the ModelBinding power of the Routing Engine: ``` var queryValue = Request.RequestUri.ParseQueryString(); string dateOfLog = queryValue["dateOfLog"]; ``` Please tell me how to create a Route definition that will use ModelBinding correctly and map my custom url to the controller's parameters.