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.