I have a custom controller extension to return an Excel file as an HttpContext response.
My controller action is as follows:
public ActionResult ExportToExcel()
{
return this.Excel(headers, results, filename);
}
This works perfectly with a normal MVC callback.
I'm trying to create a jQuery UI dialog where the user can enter the file name and press Export. When the Export button is clicked the MVC action will get called in the controller, but the file doesn't get responded in the browser.
My dialog code is:
$("#export-excel").dialog({
autoOpen: false,
modal: true,
title: "Export to Excel",
buttons: {
Export: function () {
$.post("/Search/ExportToExcel",
function () {
$("#export-excel").dialog("close");
});
}
}
});
$("#export-excel-button").click(function () {
$("#export-excel").dialog("open");
return false;
});
And the html:
<div id="export-excel" style="display: none;">
Filename:
<input type="text" value="Results.xls"/>
</div>
<input type="button" value="Export" id="export-excel-button" />