0

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>

2
  • Figured it out. Just had to set the location in the javascript. Commented Jun 20, 2013 at 19:00
  • 1
    Post that as an answer.
    – ChrisF
    Commented Jun 20, 2013 at 19:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.