簡體   English   中英

為什么ASP.NET MVC在從IE而不是firefox發布數據時會抱怨null參數?

[英]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接受

參考: http//www.w3schools.com/jsref/jsref_toisostring.asp

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM