Asp.net mvc 4 MVC在弹出窗口中打开PDF
在我的应用程序中,我的解决方案中有一个pdf文档,当用户单击特定按钮时,该文档必须在弹出窗口中打开。我可以通过返回filestream对象在同一个窗口中打开它Asp.net mvc 4 MVC在弹出窗口中打开PDF,asp.net-mvc-4,Asp.net Mvc 4,在我的应用程序中,我的解决方案中有一个pdf文档,当用户单击特定按钮时,该文档必须在弹出窗口中打开。我可以通过返回filestream对象在同一个窗口中打开它 public ActionResult ShowPdf() { if (System.IO.File.Exists(Server.MapPath("~/downloads/MyPdf.pdf"))) { string pathSource = Server.MapPath("
public ActionResult ShowPdf()
{
if (System.IO.File.Exists(Server.MapPath("~/downloads/MyPdf.pdf")))
{
string pathSource = Server.MapPath("~/downloads/MyPdf.pdf");
FileStream fsSource = new FileStream(pathSource, FileMode.Open, FileAccess.Read);
return new FileStreamResult(fsSource, "application/pdf");
}
else
{
return RedirectToAction("Index", "User");
}
}
如何在弹出窗口中加载相同的内容
提前感谢,这取决于您如何从客户端调用此控制器操作。例如,如果您有一个链接,您可以将
target=“\u blank”
属性添加到此锚定。例如:
@Html.ActionLink(
"Download pdf",
"ShowPdf",
"SomeController",
null,
new { target = "_blank" }
)
或者,如果使用javascript调用控制器操作,则可以使用函数