如何在MVC中的动作结果中返回PDF

编程入门 行业动态 更新时间:2024-10-19 12:33:24
本文介绍了如何在MVC中的动作结果中返回PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有点问题让我解决这个问题。我有一个ajax调用,应该呈现一个加载PDF的iframe。 PDF是使用托管在其他环境中的Apache FOP生成的。到目前为止我所拥有的是:

I have a little problem getting my head around this problem. I have an ajax call that should render an iframe which loads a PDF. The PDF is generated using Apache FOP hosted in another environment. What I have so far is:

在控制器动作中(iFrame指向的src元素),代码片段为:

in the controller action (where the src element of the iFrame points), the code snippet is:

var targetStream = new MemoryStream(); using (var response = FOPrequest.GetResponse()) // response from FOP { using (var stream = response.GetResponseStream()) { stream.CopyTo(targetStream); } } return new FileStreamResult(targetStream, "application/pdf");

但是,这不能按预期工作。将按预期填充流,但PDF不会在iFrame中呈现。 我得到的Http响应代码为200(OK)。

However, this does not work as expected. The stream is populated as expected, but the PDF does not render in the iFrame. I get a Http response code of 200 (OK).

我很感激任何帮助。

推荐答案

你使用MVC FileContentResult 返回ActionResult 例如:

You use MVC FileContentResult to return ActionResult For example:

return File(fileArray, contentType, fileName)

另一个堆栈答案

更多推荐

如何在MVC中的动作结果中返回PDF

本文发布于:2023-11-24 21:01:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动作   如何在   MVC   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!