When passing js Date objects to my ASP.NET Web Api controller, I always get null. I have tried passing strings, array of string, timespan - all those works, except Date. When inspecting the request, the date is passed like this:
date:"2014-03-13T15:00:00.000Z"
In angular:
$http({
method: 'get',
url: 'api/stuff',
params: {
date: new Date()
}
);
In my ApiController:
public IEnumerable<StuffResponse> Get(
[FromUri] DateTime? date
){ ... }
What is the correct way to pass dates?
This works for me:
$http({
method: 'get',
url: 'api/stuff',
params: {
date: $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss")
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With