0

我不确定为什么会发生这种情况,但是当我从“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>

4

0 回答 0