Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core mvc 显示wwwroot文件夹中的word文档,而不是下载:ASP.Net Core_Asp.net Core Mvc - Fatal编程技术网

Asp.net core mvc 显示wwwroot文件夹中的word文档,而不是下载:ASP.Net Core

Asp.net core mvc 显示wwwroot文件夹中的word文档,而不是下载:ASP.Net Core,asp.net-core-mvc,Asp.net Core Mvc,我正在尝试在iframe中显示.NET MVC核心应用程序文件夹中wwwroot文件夹中的文档 情景: 我的Razor页面上有一个文档列表:MyRazor.cshtml,每个列表都有一个按钮。当我单击该按钮时,它会使用单个文档的Id显示其详细信息 当页面加载时,文档将被下载,而不是显示在iframe src中 控制器: public ActionResult GetArticles(int id) { try { Articles

我正在尝试在iframe中显示.NET MVC核心应用程序文件夹中wwwroot文件夹中的文档

情景:

我的Razor页面上有一个文档列表:MyRazor.cshtml,每个列表都有一个按钮。当我单击该按钮时,它会使用单个文档的Id显示其详细信息

当页面加载时,文档将被下载,而不是显示在iframe src中

控制器:

public ActionResult GetArticles(int id)
    {
        try
        {
            Articles getArticles = _articleRepository.GetArticles(id);
            return View(getArticles);
        }
        catch (Exception)
        {

            return NotFound();
        }
    }
<div class="card">
    <iframe id="documentViewer" src="~/docs/@Html.DisplayFor(model => model.WordDocumentFile)" width="100%" height="700px;" frameborder="0"></iframe>
</div>
查看:

public ActionResult GetArticles(int id)
    {
        try
        {
            Articles getArticles = _articleRepository.GetArticles(id);
            return View(getArticles);
        }
        catch (Exception)
        {

            return NotFound();
        }
    }
<div class="card">
    <iframe id="documentViewer" src="~/docs/@Html.DisplayFor(model => model.WordDocumentFile)" width="100%" height="700px;" frameborder="0"></iframe>
</div>

这是不可取的。我只想在iframe中显示该文档


我缺少什么?

因为web浏览器不知道文档文件,所以需要将它们转换为HTML或PDF。

最好的方法是将
PDF
文件存储在相应的文件夹中,然后直接读取PDF文件以显示文档内容,而不是下载文件


你也可以参考这一点:

余永庆的回答有点像是这样说的,但我只想详细说明一下,如果PDF文件在你的
wwwroot
文件夹中,你所需要做的就是

在视图中,
~/
已经与存储在
wwwroot