0

I have a javascript function from which I need to call a controller action to return the filestream to the UI . I am not getting the open,save and save as dialog box. In the cshtml file I have following function:DownloadFile

var selectUrl = '@Url.Action("Download", "Controller")' + "/" + filedetails; 
$.post(selectUrl);

and in the controller I have the following code:

public ActionResult Download(string id)
return File(downloadStream, "application/octet-stream",fileName);

Please let me know is this the correct way of calling.

Mihai Labo
  • 1,082
  • 2
  • 16
  • 40
user1400915
  • 1,933
  • 6
  • 29
  • 55
  • You dont see the dialog box, but what exactly happens when you call that javascript function.------------ Please edit your post and correctly use code tag. – Mohayemin Jun 29 '12 at 11:08
  • On click of the button I want to call the ActionResult which returns File(downloadStream, "application/octet-stream",fileName); so that the user can see the open dialog box. – user1400915 Jun 29 '12 at 11:11
  • I understand what you want, I am asking what is happening now when you click the button? Nothing happens? – Mohayemin Jun 29 '12 at 11:12
  • Nothing is happening ,its just executing and nothing is displayed in UI – user1400915 Jun 29 '12 at 11:16
  • Use `var selectUrl = '@Url.Action("Download", "Controller", new {id=filedetails})'` and tell me if it works. Apparently, you are not going to the correct url. Put a debug pointer in your Download Action to see if your request reach there. – Mohayemin Jun 29 '12 at 11:27
  • Ya I am able to hit the action but dont know why its not returning the dialog box. – user1400915 Jun 29 '12 at 11:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13218/discussion-between-user1400915-and-mohayemin) – user1400915 Jun 29 '12 at 11:50

1 Answers1

1

try this way :ActionResult

 public ActionResult Download(string id) 
    {
          var cd = new System.Net.Mime.ContentDisposition
                    {

                        FileName = "imagefilename",
                        Inline = false,
                    };
        Response.AppendHeader("Content-Disposition", cd.ToString());
        string contentType = "application/octet-stream";
          // you are downloadStream
        return File(downloadStream, contentType);
    }

link here

Community
  • 1
  • 1
Tamkeen
  • 448
  • 4
  • 10