Reputation: 876
Off the bat: I am new to using asp.net mvc 4.
I am have a action that creates a excel file and then converts it to PDF.
From View
@Html.ActionLink("Generate Invoice", "genInvoice", new { id = item.invoiceID }) |
Action:
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);
}
Now I want to to eventually download the PDF file and then return to the index view. It goes to the Index view prints the html etc etc but then the window stays as a white screen with the url: /Invoice/genInvoice/1
Any idea how I can go about doing this? (Going back to the Index view after PDF generation, also downloading it)
Upvotes: 4
Views: 1773
Reputation: 876
I am sorry, I fixed the white screen problem. While attempting to do the PDF download
//Response.AppendHeader("Content-Disposition", "inline; filename="+invoiceClient+".pdf");
//Return File(output, "application/pdf");
//Response.Flush();
//Response.End();
Response.End() was not commented out and that stopped it I guess.
Now the problem is how to open the PDF in a separate tab and return to index in the current with the above code.
EDIT: Decided the file can just be downloaded.
public FileResult genInvoice(int id = 0)
{
//More code
Response.AppendHeader("Content-Disposition", "attachment; filename="+pathName+".pdf");
return File(websitePath + "\\" + invoiceClient + ".pdf", "application/pdf");
}
Upvotes: 1