奇怪的事情发生在这里.
我有一些JS发布到ASP.NET MVC ActionMethod,它可以在除IE的任何版本之外的每个浏览器中查找.
有问题的代码如下:
$.ajax({ url: path,type: 'POST',data: { team: team_copy[team_copy.length - 1],queryDate: d.toUTCString(),newOutlets: newOutlets },success: function (MyResponSEObject) { holder.append(MyResponSEObject.content); //locate active section and click to show new content - its a mess,but it works //activeMenu.click(); MessageSystem.showMessage("Target Data System",MyResponSEObject.message,false); if (team_copy.length > 1) { team_copy.pop(); $('#actualprogress').animate({ width: '+=' + TargetReports.progressratio + '%' },'slow'); TargetReports.getTeamData(team_copy,d,newOutlets); } else { MessageSystem.showMessage("Complete","All Data Fetched",false); $('#show-calendar-selection').fadeIn(); TargetReports.buildTotalsTable("daysandcalls","daysandcallstotal"); TargetReports.buildTotalsTable("volumeanddistribution","volumeanddistributiontotal"); TargetReports.buildTotalsTable("outletactivation","outletactivationtotal"); TargetReports.buildTotalsTable("promotion","promotiontotal"); //$('#progress').fadeOut().remove(); $('#results-options').fadeIn(); $('#total-holder').fadeIn(); activeMenu.click(); //update link to download file var hidden = $('.hidden-information').first(); var newOutlets = encodeURIComponent($('input[name="newoutlets"]',hidden).val()); var queryDate = encodeURIComponent($('input[name="enddate"]',hidden).val()); var anchor = $('#get-target-reports'); var link = anchor.attr('href'); link = "/manager/TargetResults.csv?endDate=" + queryDate + "&newOutlets=" + newOutlets; anchor.attr('href',link); } } });
Action Method签名如下所示:
public ActionResult GenerateTargetData(int team,DateTime queryDate,bool forceRegen = false,bool newOutlets = false)
在IE .NET中运行时,会抱怨queryDate参数的空条目.使用IE中的调试工具我可以看到请求体看起来如下:
team=7&queryDate=Mon%2C+29+Nov+2010+23%3A15%3A39+UTC&newOutlets=false
在Firefox中,它有效:
team=7&queryDate=Mon%2C+29+Nov+2010+23%3A10%3A46+UTC&newOutlets=false
我真的不知道这里有什么.所有帮助赞赏!
解决方法
您的问题似乎是因为ASP.net MVC模型绑定器将接受ISO8601格式的日期时间.
If the time is in UTC,add a ‘Z’ directly after the time without a space. ‘Z’ is the zone designator for the zero UTC offset. “09:30 UTC” is therefore represented as “09:30Z” or “0930Z”. “14:45:15 UTC” would be “14:45:15Z” or “144515Z”.
我已经检查过chrome 12.0.733.0 dev,Firefox 4,IE 9.如果你调用javascript toUTCString(),不同的浏览器返回不同的东西. Chrome和Firefox将返回“Wed,20 Apr 2011 20:31:11 GMT”,只有IE返回“Wed,2011年4月20日20:31:11 UTC”
d.toUTCString().replace(‘ UTC’,’Z’) will work for you.