c# - 在特定页面上的 iframe 中打开 PDF 文件
问题描述
我有一个 iframe,它使用 Url.Action 从动作控制器打开 PDF。是否可以在特定页面上打开此 PDF?由模型中的值确定,例如 @Model.FilePage
框架:
<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");
}
解决方案
在特定页面上打开,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>
推荐阅读
- python - 在 Python 中执行命令时发生错误
- python - 无法在 hvplot 轴上绘制 datetime64[ns]('pandas_datetime_types' 未定义'错误)
- react-select - 你好,点击编辑按钮,之前选择的数据在
硬刷新时不显示 - discord.js - 如何在 discord.js 上添加服务器统计通道
- node.js - 实现这种postgres + redis数据检索的“正确”方法是什么?
- ssh - 阻止 ssh-agent 永久保存密码
- android - 尝试加载 PDF URL 时没有可用的预览
- r - 如何分享我用 R 制作的交互式地图?
- laravel - Laravel 数据透视表批量插入多个字段
- oracle - 使用 oracle toad 获取 Oracle 查看代码信息