4

すぐに: 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生成後、インデックスビューに戻り、ダウンロードも)

4

1 に答える 1

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");
}
于 2012-11-30T10:44:24.547 に答える