admin管理员组文章数量:1240583
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?
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?
Share Improve this question edited Apr 10, 2014 at 19:36 andyp 6,2693 gold badges40 silver badges55 bronze badges asked Mar 3, 2014 at 14:22 TryllingTrylling 2132 gold badges4 silver badges9 bronze badges2 Answers
Reset to default 13This works for me:
$http({
method: 'get',
url: 'api/stuff',
params: {
date: $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss")
}
);
The formatting of the date in your Javascript is not patible with .NET DateTime parsing. See here for valid formats.
http://msdn.microsoft./en-us/library/az4se3k1(v=vs.110).aspx
本文标签: cPassing Date in AngularJS http get to ASPNET Web ApiStack Overflow
版权声明:本文标题:c# - Passing Date in AngularJS $http get to ASP.NET Web Api - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740075030a2223241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论