[英]Why does ASP.NET MVC complain of a null parameter when data is posted from IE and NOT firefox?
奇怪的事情发生在这里。
我有一些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格式的日期时间。
如果时间是UTC,则在没有空格的时间之后直接添加“Z”。 'Z'是零UTC偏移的区域指示符。 因此,“09:30 UTC”表示为“09:30Z”或“0930Z”。 “14:45:15 UTC”将是“14:45:15Z”或“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')对你有用。
采用
queryDate: d.toISOString()
代替
queryDate: d.toUTCString()
这根据ISO标准(类似于2012-07-09T15:44:03.114Z)格式化日期,并且很高兴被ASP.NET MVC接受
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.