关闭蝙蝠:我是使用asp.net mvc 4的新手。
我有一个创建excel文件的操作,然后将其转换为PDF。
从视图
@Html.ActionLink("Generate Invoice", "genInvoice", new { id = item.invoiceID }) |
动作:
public ActionResult genInvoice(int id = 0)
{
var invoiceItems = from k in db.InvoiceItems
where k.invoiceID == id
select k;
string invoiceClient = (from kk in db.Invoices
where kk.invoiceID == id
select kk.clientName).Single();
invoiceClient = invoiceClient + "_" + DateTime.Now.ToString("ddd dd MMM yyyy hhTmm");
string websitePath = Request.PhysicalApplicationPath;
string pathName = websitePath + "\\" + invoiceClient ;
generateInvoice(invoiceItems, pathName + ".xlsx", id);
convertToPDF(pathName, invoiceClient);
//Response.AppendHeader("Content-Disposition", "attachment");
var viewModel = new InvoiceItemAdd();
viewModel.Invoices = db.Invoices
.Include(i => i.InvoiceItems)
.OrderBy(i => i.invoiceID);
return View("Index", viewModel);
//return RedirectToAction("Index",viewModel);
}
现在我想最终下载PDF文件,然后返回索引视图。 它进入索引视图打印html等,但然后窗口保持为白色屏幕与url:/ Invoice / genInvoice / 1
知道我怎么能这样做吗? (在生成PDF之后返回索引视图,同时下载它)
答案 0 :(得分:1)
对不起,我修复了白屏问题。在尝试进行PDF下载时
//Response.AppendHeader("Content-Disposition", "inline; filename="+invoiceClient+".pdf");
//Return File(output, "application/pdf");
//Response.Flush();
//Response.End();
Response.End()没有被注释掉,我想这就停止了。
现在问题是如何在单独的选项卡中打开PDF并返回当前的索引 用上面的代码。
编辑: 决定文件可以下载。
public FileResult genInvoice(int id = 0)
{
//More code
Response.AppendHeader("Content-Disposition", "attachment; filename="+pathName+".pdf");
return File(websitePath + "\\" + invoiceClient + ".pdf", "application/pdf");
}