I have an action that returns (downloads) an excel file in the following manner:
public IActionResult CreateExcelFile(string id, int xx, string start, string end) {
//Some additional code...
// ....
// ....
var file = File(doc, "application/vnd.ms-excel");
file.FileDownloadName = filename + " " + id + ".xlsx";
return file;
}
So far, I have triggered this action from a view like this:
<div id="myDiv">Some Content</div>
And lastly the JavaScript:
$(function excelFunction() {
$('#myDiv').click(function () {
alert("Initiate excel export")
var start = $('#startDateTextBox').val();
var end = $('#endDateTextBox').val();
$.ajax({
type: 'GET',
url: '/Customer/CreateExcelFile',
data: { id: 'FVM10000', xx: '4', start: start, end: end },
success: function (response) {
if (response.type == "success") {
alert("success")
}
else {
// Do something else
alert("failure")
}
}
});
});
});
I enter the debugging mode and see that the action is indeed called with the correct parameters, however, after the action is executed, no file is returned (or downloaded). I get an alert message saying "failure", which indicates that the response was not completed.
Any ideas what I am doing wrong?