2013-02-25 219 views
1

在我的应用程序中,我在我的解决方案中有一个pdf文档,当用户单击某个特定按钮时,文档必须在弹出窗口中打开。我可以通过返回文件流对象在同一窗口中打开它。我使用的代码。MVC在弹出窗口中打开PDF

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"); 
     } 
    } 

我怎样才能加载相同的弹出式窗口中提前

回答

3

感谢这将取决于你如何调用从客户端该控制器动作。例如,如果您有链接,则可以将target="_blank"属性添加到此锚点。例如:

@Html.ActionLink(
    "Download pdf", 
    "ShowPdf", 
    "SomeController", 
    null, 
    new { target = "_blank" } 
) 

或者,如果你正在使用JavaScript来调用控制器操作,您可以使用window.open功能。

相关问题