I've got a WebAPI action that looks like so:
[Route("api/values/{id}")]
public async Task<HttpResponseMessage> Delete(string id, DateTimeOffset date) {
//do stuff
}
But when I invoke this from a HttpClient
instance, making a URL like:
string.Format("http://localhost:1234/api/values/1?date={0}", System.Net.WebUtility.UrlEncode(DateTimeOffset.Now.ToString()));
// -> "http://localhost:1234/api/values/1?date=17%2F02%2F2015+7%3A18%3A39+AM+%2B11%3A00"
I get a 400
response back saying that the non-nullable parameter date
does not exist.
I've also tried adding the [FromUri]
attribute to the parameter but it still doesn't map through. If I change it to be DateTimeOffset?
I can see it is left as null and looking at Request.RequestUri.Query
the value is there, just not mapped.
Finally I tried not doing a WebUtility.UrlEncode
and it made no different.