I have a WebAPI controller (TasksController) with a GET method like:
public IEnumerable<TimeUnitModel> Get(DateTime startDate, DateTime endDate, string projectCode = "")
If I call:
/api/tasks?startDate=2012%2F12%2F08&endDate=2012%2F12%2F15
then the correct result is returned.
If I call:
/api/tasks?startDate=2012%2F12%2F08&endDate=2012%2F12%2F15&projectCode=
then I get:
{"projectCode.String":"A value is required but was not present in the request."}
Here's what I have in the route config:
config.Routes.MapHttpRoute(
name: "tasks_get",
routeTemplate: "api/tasks",
defaults: new { controller = "tasks", projectCode = RouteParameter.Optional}
);
Any idea why this happens?