gpt4 book ai didi

javascript - 参数不应该为空

转载 作者:行者123 更新时间:2023-12-01 00:53:58 25 4
gpt4 key购买 nike

我在这个清晨遇到了一个有点奇怪的错误。错误很简单

The parameters dictionary contains a null entry for parameter 'FirstDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult GeneratePDF(System.DateTime, System.DateTime)' in 'TimeRegPlanner.Controllers.TimeRegistrationController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

Controller 看起来像这样

public ActionResult GeneratePDF(DateTime FirstDate, DateTime LastDate)
{
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}

这是 JavaScript:

function CreatePDF() {
var xyz = document.getElementById("regDate").valueAsDate
// var ShopDocCode = document.getElementById("werkkaart").value

var first = xyz.getDate() - xyz.getDay() + 1;
var last = first + 6; // last day is the first day + 6

var firstday = new Date(xyz.setDate(first)).toUTCString();
var lastday = new Date(xyz.setDate(last)).toUTCString();
alert(firstday);
alert(lastday);
var x = document.getElementById("checkBox").checked;
if (x === true) {
window.location = appPath + "/TimeRegistration/GeneratePDF?FirstDate=" + firstday + "&LastDate=" + lastday;
}

setTimeout(function () {
$("#dialog-Confirm").modal("hide");
}, 3000);

}

当我在第一天和最后一天进行调试和 console.log 时,我可以看到它们具有正确的值:

firstday: Mon, 24 Jun 2019 00:00:00 GMT lastday: Sun, 30 Jun 2019 00:00:00 GMT

最佳答案

除了我以前从未见过 valueAsDate 之外,我肯定会对日期进行编码并删除路径中的空格

window.location = appPath + "/TimeRegistration/GeneratePDF"+
"?FirstDate=" + encodeURIComponent(firstday) +
"&LastDate=" + encodeURIComponent(lastday);

关于javascript - 参数不应该为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56747078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com