我不确定为什么会发生这种情况,但是当我从“ActionLink”调用我的动作时它可以正常工作,但是当我从javascript调用它时它没有。两种方法都使用“ExportFile”方法,但只有“ActionLink”在下载文件时显示Chrome浏览器底部的文件,但不适用于javascript调用。下面是我的操作方法,下面是我的视图。为什么一个会起作用而另一个起作用呢?
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>