如何在视图MVC中显示.pdf文件。 [英] How can display .pdf file in view MVC.

查看:310
本文介绍了如何在视图MVC中显示.pdf文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有.pdf文件,需要在MVC5中查看浏览器

当我无法做到时



我尝试过:



< ; div id =divReportstyle =width:100%; text-align:center; height:100%overflow:hidden;> 
< div id ='PDF123'>
@ {Url.Action(DisplayPDF,PICSFS010);}

< / div>

< / div>
控制器动作:

public FileResult DisplayPDF()
{
return File(〜/ HelpFile / awstats.pdf,application / pdf);
}

< script>
< pre>< script type =text / javascript>
函数Initialize_view(){
showloader();
$ .ajax({
url:/ PICSFS010 / DisplayPDF,
cache:false,
dataType:html,
success:function(data) {
调试器;
$(#PDF123)。html(数据);
},
错误:函数(数据){
调试器;
hideloader();
}
});
}
< script>

解决方案

.ajax({
url:/ PICSFS010 / DisplayPDF,
cache:false,
dataType:html,
success:function(data){
debugger;


(#PDF123)。html(数据);
},
错误:函数(数据){
调试器;
hideloader();
}
});
}
< script>


你在这里尝试的是什么文件(〜/ HelpFile / awstats .pdf,application / pdf) #PDF123 元素内的pdf内容作为HTML内容返回...这无论如何都不会起作用,因为浏览器将尝试将其解释为HTML(毕竟你告诉它这样做)并且它当然会失败...

向用户显示文件的最简单方法是链接到它(将浏览器重定向到它),但即使这样你也无法确定文件将在何处(以及通过什么应用程序)打开...这取决于最终用户的收藏夹,因此它可以以一个内置显示器结束,第三方应用程序打开或简单下载...



如果您不想透露文件的位置,本文试图解释您如何这样做:使用Simpl流式传输文档e网页 [ ^ ]

Hi,

I have .pdf file and need to view in brower in MVC5
When i am not able to do

What I have tried:

<div id="divReport" style="width:100%;text-align:center; height:100% overflow:hidden;">
    <div id='PDF123'>
       @{Url.Action("DisplayPDF", "PICSFS010");}
   
    </div>

</div>
Controller Action :

public FileResult DisplayPDF()
        {
          return File("~/HelpFile/awstats.pdf", "application/pdf");
        }

<script>
<pre><script type="text/javascript">
  function Initialize_view() {
        showloader();
        $.ajax({
            url: "/PICSFS010/DisplayPDF",
            cache: false,
            dataType: "html",
            success: function (data) {
                debugger;
                $("#PDF123").html(data);
            },
            error: function (data) {
                debugger;
                hideloader();
            }
        });
    }
<script>

解决方案

.ajax({ url: "/PICSFS010/DisplayPDF", cache: false, dataType: "html", success: function (data) { debugger;


("#PDF123").html(data); }, error: function (data) { debugger; hideloader(); } }); } <script>


What are you tried here is put whatever File("~/HelpFile/awstats.pdf", "application/pdf") returns (the content of the pdf?) inside the #PDF123 element as HTML content... That will not work anyway, as the browser will try to interpret it as HTML (after all you told it to do so) and it will fail of course...
The most simple way to show the user a file is to link to it (redirect the browser to it), however even then you can not be sure where (and by what application) the file will be opened... That's depends on the end user's favorites, so it can end with an in-bowser display, with a 3rd party application opening or with simple download...

In case you do not want to reveal the location of the file, this article try to explain how you can do that: Stream Your Documents Using Simple Web Page[^]


这篇关于如何在视图MVC中显示.pdf文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆