无法在MVC4中使用Rotativa下载PDF文件 [英] Unable to download PDF file with Rotativa in MVC4

查看:100
本文介绍了无法在MVC4中使用Rotativa下载PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rotativa将Razor视图转换为PDF.

I am using Rotativa to turn a Razor view into a PDF.

PDF文件未下载.

我可以在Fiddler中看到它,但是浏览器没有提示下载-我已经在IE和Chrome上尝试过.

I can see it in Fiddler but the browser is not prompting for download - I have tried this with both IE and Chrome.

我还尝试使用

I also tried to download the file to a physical path using the solution in this question here. but that didn't work either because of the system couldn't access the folder (Access Denied).

这是我的代码:

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;

}

我想知道为什么会发生这种情况-单击按钮,它调用print ActionResult方法-没有错误消息(我将其包装在try and catch块中).我已经在同事的PC上尝试过了,这是同样的问题!

I wonder why is this happening - I click the button, it calls the print ActionResult method - no error messages (I wrapped this in a try and catch block). I have tried this on a colleague PC and it was the same issue!

非常感谢.

推荐答案

问题是我正在通过Ajax帖子在按钮单击事件上调用ActionResult print()方法.这显然行不通.

The issue was that I was calling the ActionResult print() method on a button click event through an Ajax post. This apparently doesn't work.

如果您将按钮替换为链接,该链接应该起作用,该链接的URL中包含print()方法.即mvc链接的工作方式.

It should work if you replace the button with a link, which has the print() mehtod in its URL; i.e., just the way mvc links work..

这篇关于无法在MVC4中使用Rotativa下载PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆