0

我有一个 javascript 函数,我需要从中调用控制器操作以将文件流返回到 UI。我没有打开、保存和另存为对话框。在 cshtml 文件中,我有以下功能:DownloadFile

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

在控制器中我有以下代码:

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

请让我知道这是正确的呼叫方式。

4

1 回答 1

1

试试这种方式: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);
    }

链接在这里

于 2012-06-29T11:08:08.387 回答