pdf 查看器的 MVC 控件不一致


<object id='pdfbox' style="width:900px; height:800px;" type="application/pdf" 
    data="@Url.Action("Action", "Controller", new { sID = this.Model.sID })">
</object>

此控件用于在视图中显示 pdf 文件。

此控件在某些系统中工作正常,但在构建和其他一些机器中,它不起作用。是否需要安装某些东西?

通过一番搜索,我找到了这个:

您可以将 PDF 嵌入到分部

视图中,然后使用表单提交按钮上的 PDF 通过 ajax 更新分部视图。

@model Test.Models.ViewModel
<style type="text/css">
#pdfbox
{
    width:600px;
    height:400px;
    border: 5px solid #ccc;
}
</style>
<object id='pdfbox' type="application/pdf" data="@Url.Action("GeneratePDF", "Home", Model)">
    Click @Html.ActionLink("here", "GeneratePDF", "Home") to view the file.
</object>  

//控制器

public ActionResult GeneratePDF(ViewModel model)
    {
        byte[] bytes = OpenPDFAndGetBytes("Thepdfname");
        return File(bytes, "application/pdf");
    }
    public ActionResult RenderPDF(LabelViewModel model)
    {
        return PartialView(model);
    }
//main view

@using (Ajax.BeginForm("RenderPDF", "Home", new AjaxOptions { UpdateTargetId = "pdf" }))
{
    <table>
        <tr>
            <td>
                <fieldset>
                    <legend>Fill the form:</legend>
                        Some form junk can go here
                    <br />
                    <input type="submit" value="Display PDF" />
                </fieldset>
            </td>
            <td>
                <div id='pdf'>
                    @{
                        Html.RenderPartial("RenderPDF", Model);
                    }
                </div>
            </td>
        </tr>
    </table>
}

源器

最新更新