【问题标题】:opening PDF file in iframe on certain page在特定页面上的 iframe 中打开 PDF 文件
【发布时间】:2020-03-29 15:00:46
【问题描述】:

我有一个 iframe,它使用 Url.Action 从动作控制器打开 PDF。是否可以在特定页面上打开此 PDF?由模型中的值确定,例如@Model.FilePage

iframe:

        <iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })"></iframe>

控制器动作:

public ActionResult OpenPDF(int? id)
        {
            CompletedCamp completedCamp = db.CompletedCamps.Find(id);
            string filepath = Server.MapPath(Path.Combine("~/Surveys/" + completedCamp.SurveyName));
            return File(filepath, "application/pdf");
        }

【问题讨论】:

  • File(filepath, "application/pdf"); 返回什么?如果返回 pdf 的链接,那么它可以工作。如果返回数据,将不起作用。
  • @Artistos 它返回一个 PDF 文件
  • @Aristos 知道如何传递页码吗?
  • 谢谢@Aristos。您知道是否可以添加到 Url.Action 方法?即类似 src="@Url.Action("OpenPDF", new { id = 8 }) +#page4"

标签: c# asp.net asp.net-mvc iframe


【解决方案1】:

要在特定页面打开,add #page=[page number]到src末尾

<iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })#page=4"></iframe>

如果页码应该来自模型,那么做

public ActionResult Index()
{
    MyViewModel m = new MyViewModel() { FilePage = 4 }; 
    return View(m);
}

...
@model MVC.MyViewModel 

<iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })#page=@Model.FilePage"></iframe>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 2020-10-11
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    相关资源
    最近更新 更多