这应该是一个简单的答案,但由于我是MVC的新手,我还不完全知道该怎么做:我想通过向浏览器发送PDF来响应用户点击链接。
- I have a string of IDs on the page that I need to post back to the method so that it can generate the requested content.
- I can build the PDF as a memory stream exposed to the controller.
- I want the user to stay on the same page on which they clicked the link and be presented with the "Save to..." dialog.
假设我的控制器名为Invoice,方法为DownloadInvoice,那么我应该在视图中放些什么来发回ID(字符串),以及我如何响应此回发?
我能简单地回答一下吗
return new FileStreamResult(generatedInvoice.Stream, "application/pdf");
或者我需要将查看器引导到另一个具有完整
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
Response.Buffer = true;
Model.Stream.WriteTo(Response.OutputStream);
Response.End();
?