小编Fai*_*pop的帖子

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

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

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

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");
Run Code Online (Sandbox Code Playgroud)

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

我会感激任何帮助.

c# pdf ajax asp.net-mvc iframe

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

ajax ×1

asp.net-mvc ×1

c# ×1

iframe ×1

pdf ×1