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.

7
  • 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. Commented Jun 29, 2012 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. Commented Jun 29, 2012 at 11:11
  • I understand what you want, I am asking what is happening now when you click the button? Nothing happens? Commented Jun 29, 2012 at 11:12
  • Nothing is happening ,its just executing and nothing is displayed in UI Commented Jun 29, 2012 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. Commented Jun 29, 2012 at 11:27

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

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.