JQuery message with FileStreamResult as return value

I am new to jQuery and asp.net mvc. My problem is that I call a method in the controller that returns a FileStreamResult. This works fine, but when I call it with a jQuery column, it doesn't work. I can see with the debugging tool vs that the program is superseding the method. So I think this has something to do with the fact that my jQuery call should take care of the returned parameter? Somenoe?

JQuery Code:

    <script type="text/javascript">
    function createPPT() {
            $.post("<%= Url.Action( "DownloadAsPowerpoint", "RightMenu" )%>");
    }
    </script>

Method in the controller:

    public ActionResult DownloadAsPowerpoint()
    {
        Stream stream; 
        //...
        HttpContext.Response.AddHeader("content-disposition", "attachment; filename=presentation.pptx");

        return new FileStreamResult(stream, "application/pptx");
    }

Can someone explain and give me some sample code?

+5
source share
1 answer

Use the $ .ajax () method because you are not sending any parameters:

    function createPPT() {
        //Show waiting dialog here
        $.ajax({
            url: '<%=Url.Action("DownloadAsPowerpoint") %>',
            method:'GET',
            success: function (fileStream) {
                //Hide waiting dialog here
                alert(fileStream); //This is your filestream
            }
        });
        return false;
    }
+3
source

All Articles