当我尝试使用MVC下载pdf时,它只是打开一个空白页面而什么都不做

时间:2013-08-16 13:59:23

标签: c# asp.net-mvc jquery-mobile pdf

当我进行此调用时,它会返回内容,正确的mime类型和文件名。它只是不会下载。

如果有人对如何解决这个问题有任何想法,我们将非常感谢您的帮助。

public FileResult Download()
{
  if (HelperClass.SessionNotExpired(Session))
  {
    string caseNumber = Request.Params["CaseNumber"] as string;
    string fileName = Request.Params["FileName"] as string;
    if (!String.IsNullOrEmpty(caseNumber) && !String.IsNullOrEmpty(fileName))
    {
      Document doc = DropBox.Get(caseNumber, fileName, DocumentServiceRequestCodes.WEB,          (string)Session[HelperClass.EMAIL], (string)Session[HelperClass.PASSWORD]);
      var cd = new System.Net.Mime.ContentDisposition
      {
        // for example foo.bak
        FileName = doc.FileName,

        // always prompt the user for downloading, set to true if you want 
        // the browser to try to show the file inline
        Inline = false,
      };
      Response.AppendHeader("Content-Disposition", cd.ToString());

      return File(doc.Contents, GetMimeType(fileName), fileName);
    }
  }
  return null;
}

1 个答案:

答案 0 :(得分:0)

如果内容是流,请尝试手动设置其位置?

stream.Seek(0, SeekOrigin.Begin);

stream.Position = 0;