用于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查看器的MVC控件不一致

这种控制在一些系统中工作正常,但在构建和其他一些机器中,它不工作。是否需要安装?

+0

知道了,机器已经安装了PDF阅读器? – Paparazzi

+0

是安装Adobe Reader X1 – user1907849

随着一点点的搜索,我发现这个:

您可以嵌入在一个局部视图的PDF然后更新通过AJAX与窗体上的PDF的局部视图提交按钮。

@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