我正在使用Rotativa將剃刀視圖變成PDF。無法在MVC4中使用Rotativa下載PDF文件
PDF文件未下載。
我可以在Fiddler中看到它,但瀏覽器不提示下載 - 我已經在IE和Chrome上試過了。
我也嘗試使用this question here.中的解決方案將文件下載到物理路徑,但由於系統無法訪問文件夾(拒絕訪問),該文件無法工作。
這裏是我的代碼:
public ActionResult Index()
{
var model = new CustomerDashboardVM();
return View("Index", model);
}
public ActionResult print(int voucherID)
{
var pdf = new ActionAsPdf("Index", new { voucherID}) { FileName = "testInvoice.pdf", PageSize = Rotativa.Options.Size.A4};
// RotativaHelper.SaveHttpResponseAsFile("http://localhost:65425/BlankDashboard", Server.MapPath("~\\PdfDownloads"));
return pdf;
}
我不知道爲什麼會這樣 - 我按一下按鈕,它會調用打印ActionResult的方法 - 沒有錯誤信息(我的一個嘗試,catch塊包裹着這一點)。我在同事的個人電腦上試過這個,這是同樣的問題!
非常感謝。
而是** ActionAsPdf的**,你可以使用** ViewAsPdf **。所以你的代碼看起來像這樣 - 返回新的ViewAsPdf(「Index.cshtml」,new {voucherID}) { FileName =「testInvoice.pdf」, CustomSwitches =「--print-media-type --header-center \ 「text \」「 } ;.對格式問題感到抱歉。 –
@KrishnrajRana謝謝隊友。這沒有用;它詢問了視圖的視圖模型(Index.cshtml)。我真的希望它顯示一個行動的結果,所以我想知道爲什麼這不會與ActionAsPdf工作 - 它適用於其他項目! –
好的,告訴我你的** CustomerDashboardVM()**返回什麼?它是否返回通用列表?我在說這行 - ** var model = new CustomerDashboardVM(); **在Index()方法中 –