Làm cho nó như một tập tin đính kèm và cung cấp cho nó một tên tập tin khi trả lại kết quả:
protected ActionResult ViewPdf(string pageTitle, string viewName, object model)
{
// Render the view html to a string.
string htmlText = this.htmlViewRenderer.RenderViewToString(this, viewName, model);
// Let the html be rendered into a PDF document through iTextSharp.
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
// Return the PDF as a binary stream to the client.
return File(buffer, "application/pdf", "myfile.pdf");
}
Điều gì làm cho các tập tin xuất hiện như tập tin đính kèm và bật lên hộp thoại Save As là dòng sau:
return File(buffer, "application/pdf", "myfile.pdf");
Nguồn
2013-08-27 15:58:30
Xin vui lòng gửi mã có liên quan. Bạn không nên mong đợi mọi người đến đó và đọc toàn bộ bài báo. –