3

我有一个带有 target="_blank" 的表单,可以在新选项卡中发布、处理和返回 PDF 文件,问题是:

当我第一次做时,一切都好,但是当我再次做时,它不是打开一个新标签,而是用新内容替换旧标签!

如果我使用的是 Internet Explorer,它会将我的参数发布为 null,在这种情况下,我需要关闭新选项卡,然后再做一次

控制器:

public ActionResult SubmitReport(string parameter)
{
   // all the code
   return File(stream, "application/pdf");
}

看法:

@using (Html.BeginForm("SubmitReport", "ResumoPagamentos", FormMethod.Post, new { area = "CI3S", @target = "_Blank" }))
{
  // etc.. etc...
}
4

2 回答 2

5

HTMLtarget值区分大小写。

_Blank(capital B) 不是特殊_blank值(它总是打开一个新选项卡),而是一个名为 的选项卡_Blank,如果存在,它将被重用。

于 2013-05-02T14:29:43.210 回答
0

首先创建一个超链接以打开相应的文件单击超链接将导致在浏览器的新选项卡中打开 pdf 文件

public ActionResult OpenFile(int id)
{
    var Filename = objdb.Pdfs.Where(x => x.Id == id).Select(x => x.PdfFile).FirstOrDefault();
    if (Filename != null)
    {
        string path = Server.MapPath("/FileStorage/" + Filename);
        if (System.IO.File.Exists(path))
        {
            Response.AppendHeader("Content-Disposition", "inline; filename=something.pdf");
            return File(path, Filename);
            //return File(path, "multipart/mixed", Filename);
            //return File(path, "application/pdf");
        }
    }
    return View();
}
于 2013-09-04T13:05:41.757 回答