用于pdf查看器的MVC控件不一致

时间:2012-12-17 15:08:33

标签: asp.net-mvc asp.net-mvc-4

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

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

这种控制在某些系统中运行良好,但在构建和其他一些机器中,它无法正常工作。是否需要安装某些东西?

1 个答案:

答案 0 :(得分:0)

通过一点搜索,我发现了这个:

您可以在部分视图中嵌入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>
}

Sourcer

相关问题