【问题标题】:When ever I try to download a pdf with MVC it just open a blank page and does nothing每当我尝试使用 MVC 下载 pdf 时,它只会打开一个空白页面并且什么都不做
【发布时间】:2013-08-16 13:59:22
【问题描述】:

当我进行此调用时,它会返回内容、正确的 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;
}

【问题讨论】:

  • 您确定doc 不为NULL 吗?
  • doc.Contents的数据类型是什么?
  • Not null 是一个字节数组。

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


【解决方案1】:

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

stream.Seek(0, SeekOrigin.Begin);

stream.Position = 0;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 2020-11-24
    • 2021-09-11
    • 1970-01-01
    相关资源
    最近更新 更多