我正在尝试从数据选择器中获取开始日期和结束日期,然后使用开始日期和结束日期创建列日期列表,当我硬编码其中的日期时工作正常,但是当我尝试从他们都返回null的日期选择器,这是一些代码(我也在使用MVC3和Razor,但我认为这是我做错的JS事情。)。
using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<p>
Start Date:
<input id='datepicker' name='datepicker' style="width: 85px">
End Date:
<input id='datepickerend' name='datepickerend' style="width: 85px">
@Html.ListBox("teamID", (SelectList)ViewBag.Teams, "--Select a Team--")
@Html.DropDownList("dealID", (SelectList)ViewBag.Deals, "--Select a Deal--")
<input type="submit" value="Filter" id="btnFilter" />
</p>}
<script type="text/javascript">
function FormatUkDate(dateStr) {
dateStr = dateStr.split("/");
return new Date(dateStr[2], dateStr[1] - 1, dateStr[0]);
}
</script>
<script type="text/javascript">
Date.prototype.addDays = function (days) {
var dat = new Date(this.valueOf())
dat.setDate(dat.getDate() + days);
return dat;
}
function getDates() {
// var StartDate = new Date(FormatUkDate($('#datepicker').value));
// var EndDate = new Date(FormatUkDate($('#datepickerend').value));
var StartDate = $('#datepicker').val();
var EndDate = $('#datepickerend').val();
var dateArray = new Array();
while (StartDate <= EndDate) {
dateArray.push(StartDate)
StartDate = StartDate.addDays(1);
}
return dateArray;
}
</script>
<script>
var daterange = getDates();
var grid;
var colsArray = new Array();
var columns = [
{
id: "Name", name: "Name", field: "Name"
}
];
for (i = 0; i < daterange.length; i++) {
var a = daterange[i].toString()
a = a.substring(0, 10);
columns.push({ id: a.valueOf(), name: a.valueOf(), field: a.valueOf() });
}
var options = {
enableCellNavigation: true,
enableColumnReorder: true
};
$(function () {
var myData = [];
$.getJSON('/Home/getm', function (data) {
myData = data;
grid = new Slick.Grid("#myGrid", myData, columns, options);
});
});
</script>