0
我使用asp.net mvc2(c sharp)創建一個項目。我想要創建一個鏈接來在navigateur中打開pdf, pdf exixte在我的數據庫中。創建一個鏈接,在asp.net mvc2導航器中打開pdf
我使用asp.net mvc2(c sharp)創建一個項目。我想要創建一個鏈接來在navigateur中打開pdf, pdf exixte在我的數據庫中。創建一個鏈接,在asp.net mvc2導航器中打開pdf
你可以設計一個控制器動作將從數據庫中讀取PDF路徑和它傳輸到響應:
public ActionResult ShowPdf()
{
string path = ... fetch path from database
if (!System.IO.File.Exists(path))
{
// the file was not found
throw new HttpException(404, "Not found");
}
return File(path, "application/pdf", "test.pdf");
}
,然後你可以創建一個鏈接,這個動作在你看來:
<%= Html.ActionLink("download pdf", "showpdf", "somecontroller") %>
thankx很多,這允許下載PDF,但希望在我的navigateur – fatma
@fatma顯示PDF,以確保數據庫中存在的文件路徑必須是相對路徑而不是物理路徑,並將該路徑分配給'你的鏈接的href' –