马上开始:我是使用 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生成后返回索引视图,也下载它)