5

I'm quite new with jquery and asp.net mvc. My problem is that I'm calling a method in a controller that returns a FileStreamResult. This is working fine, but when I'm calling it with the jQuery post it doesn't work. I can see with vs debug tool that the progam is exectuting the method. Therefor I think it has something to do with that my jQuery call should take care of the return parameter? Somenoe?

The jQuery code:

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

The method in the controller:

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

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

Could someone explain and give me some example code?

1
  • Why do you need to call it from a JavaScript function? Commented Apr 28, 2010 at 18:38

1 Answer 1

3

Use $.ajax() method, because you don't send 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;
    }
Sign up to request clarification or add additional context in comments.

6 Comments

What I'm trying to do is that I want to show a jQuery dialog while the method 'DownloadAsPowerpoint' is executing. function createPPT() { $("#dialog-confirm").dialog({ autoOpen: false, modal: true, resizable: false, closeOnEscape: false, open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); } }); $("#dialog-confirm").dialog('open'); $.post("<%= Url.Action( "DownloadAsPowerpoint", "RightMenu" )%>"); $("#dialog-confirm").dialog('close');
As I understand you are trying to add confirmation dialog, right? jQuery dialog executes async, so it is a little bit tricky to get it executed in sync and return result to onclick function. Try to use confirm function instead. I edited the post.
Confirm is a bad name (Copy & paste). I want a dialog to popup with an loader animation to popup and then disepear when my controller method is done. So fist I want to load a div with the aniamtion. Then I want to execute my controller method. Last I want to recive the filestream and hide the div with the animation.
What are you going to do with filestream in javascript?
I edited the post according to your last comment. I hope it will help
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.