ASP.NET MVC 4 Redirecting back to index view

With a bat: I'm new to using asp.net mvc 4.

I have an action that creates an excel file and then converts it to PDF.

From view

@Html.ActionLink("Generate Invoice", "genInvoice", new { id = item.invoiceID }) | 

Act:

 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 end up loading the PDF file, and then return to the index view. It goes to the Index view, prints html, etc., but then the window remains as a white screen with the URL: / Invoice / genInvoice / 1

Any idea how I can do this? (Returning to the Index view after creating the PDF files, also loading it)

+4
source share
1 answer

Sorry, I fixed the white screen issue. When trying to download in PDF

 //Response.AppendHeader("Content-Disposition", "inline; filename="+invoiceClient+".pdf"); //Return File(output, "application/pdf"); //Response.Flush(); //Response.End(); 

Response.End () was not commented out and stopped it, I think.

Now the problem is how to open the PDF in a separate tab and return to the index in the current with the above code.

EDIT: Decided the file could 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"); } 
+1
source

All Articles