0

Given a action like this:

public async Task<IHttpActionResult> GetStatus(string dataflowId, [FromUri] DateTimeOffset? lastTime = null)

and client code with uri for accessing the Action:

DateTimeOffset? last = somedatetime;
/* DO REQUEST TO */ new Uri( flow.StatusUri + (last.HasValue? "?lastTime="+last.Value.ToString():""));

an exception is raized that it cant convert to Nullable'1 for the lastTIme.

What is needed instead of ToString() on client site for webapi 2 to be able to get the datetime from querystring

{"message":"The request is invalid.","modelState":{"lastTime":["The value '1/1/1601 12:00:00 AM  00:00' is not valid for Nullable`1."]}}
Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283

1 Answers1

1

Using Uri.EscapeDataString solved the issue.

new Uri(flow.StatusUri + (last.HasValue? "?lastTime="+Uri.EscapeDataString(last.Value.ToString()):""))
Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283