請幫忙。它顯示「無法加載PDF文檔」。無法加載PDF文檔(MVC)
我沒有找到我在代碼中犯的錯誤。
這是我的代碼:
查看:
<a data-toggle="tooltip" data-placement="top" title="View" href="@Url.Action("DownloadFile", new { id = pat.ID })" target="_blank" class=" btn btn-success btn-sm">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span></a>
控制器:
public FileStreamResult DownloadFile(int id)
{
MemoryStream workStream = new MemoryStream();
DataModel DB = new DataModel();
/var content = DB._PATIENT.Where(m => m.ID == id).FirstOrDefault();
byte[] contents = (byte[])content.Result;
workStream.Write(contents, 0, contents.Length);
workStream.Position = 0;
Response.AddHeader("Content-Disposition", "inline; filename=someFile.pdf");
return new FileStreamResult(workStream, "application/pdf");
}
型號:
public int ID { get; set; }
public string PatientCode { get; set; }
public string CaseNo { get; set; }
public DateTime DatePerformed { get; set; }
public byte[] Result { get; set; }
public DateTime ExpirationDate { get; set; }
public string LaboratoryName { get; set; }
您能否發佈您的錯誤消息? –
這是一個有效的PDF字節在這裏返回,'byte [] contents =(byte [])content.Result;'? – Aruna
@Aruna,是的,它是有效的。 –