I'm not sure why this occurring, but when I call my action from a "ActionLink" it works properly, but when I call it from javascript it doesn't. Both methods get to the "ExportFile" method, but only the "ActionLink" shows the file at the bottom of the browser for Chrome when downloading a file, but it doesn't for the javascript call. Below is my action method and below that is my View. Why will one work but not the other?
public FilePathResult ExportFile()
{
string path = @"c:\1\text.xxx";
bool ex = System.IO.File.Exists(path);
return File( path,"application/text", "text.xxx");
}
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<input type="button" id="Export" value="Export" />
<%=Html.ActionLink("export", "ExportFile") %>
<div id="ExportProgress"></div>
<script type="text/javascript">
$(document).ready(function () {
$("#Export").bind("click", ExportHandler);
//alert("bind");
});
function ExportHandler() {
$.get("/DataExport/ExportFile", function () { }, 'html');
}
</script>