您好我正在尝试使用此link创建一个Excel文档,但它不会返回任何被调用的内容,它不会在代码或视图中抛出任何异常
这是controllere中的方法:
public ActionResult ExportData(string toDateTime, string fromDateTime)
{
var gv = new GridView
{
DataSource = _fttDataProvider.SelectRangeWasteRegistrations(Convert.ToDateTime(toDateTime), Convert.ToDateTime(fromDateTime), 1).ToList()
};
gv.DataBind();
return new DownloadFileActionResult(gv, "Cars.xls");
}
这是调用它的javascript
$('#SubmitExport').click(function (e) {
e.preventDefault();
var toDate = $("#toDateTime").val();
var fromDate = $("#fromDateTime").val();
$.ajax({
type: "POST",
url: ol.url("~/Home/ExportData"),
data: { "toDateTime": toDate, "fromDateTime": fromDate },
});
我使用javascript的原因是来自两个jquery ui datepickers的获取值,用于获取来往日期。
$("#fromDateTime").datepicker({
defaultDate: "+1w",
dateFormat: 'dd-mm-yy',
changeMonth: true,
numberOfMonths: 2,
onClose: function (selectedDate) {
$("#toDateTime").datepicker("option", "minDate", selectedDate);
}
});
$("#toDateTime").datepicker({
defaultDate: "+1w",
dateFormat: 'dd-mm-yy',
changeMonth: true,
numberOfMonths: 2,
onClose: function (selectedDate) {
$("#fromDateTime").datepicker("option", "maxDate", selectedDate);
}
});