【问题标题】:How to open new window with Html.BeginForm如何使用 Html.BeginForm 打开新窗口
【发布时间】:2015-04-03 09:42:44
【问题描述】:

如果提交按钮在@using Html.BeginForm 中,有什么方法可以打开一个新窗口?我尝试了以下方法,但它不起作用?

@using (Html.BeginForm("SetCol", "Document", FormMethod.Post, new {target="_blank"})){
<div class="modal-body" data-height-relative="20">
.
.
.
</div>
    <div class="modal-footer">
        <div class="pull-right">
            <input type="submit" value="Senden" class="btn btn-primary"/>
            <a href="@ViewData["closeUrl"]" class="btn btn-primary" @(ViewData["closeUrl"] == "#" ? "data-dismiss=modal" : "")>@Translations.Close</a>
        </div>
    </div>
}

输出为 PDF 文件:

<html>
  <body marginwidth="0" marginheight="0" style="background-color:  rgb(38,38,38)">
 <embed width="100%" height="100%" name="plugin" src="http://localhost:54906/Document/SetCol?id=108" type="application/pdf">
  </body>
</html>

【问题讨论】:

  • 你有错误的目标,你需要_blank而不是_self。但请不要这样做,这是糟糕的用户体验。
  • 我尝试了 blank_ 但我仍然在同一个窗口中得到结果。为什么可怕,还有什么替代方案?
  • 为什么要提交表单以打开一个新窗口?无论如何显示生成的 HTML。
  • 结果是一个 pdf 文件(也可以是 XPS、HTML 等),我希望它在一个新窗口中。目前生成的 PDF 在同一个窗口中打开

标签: html asp.net-mvc


【解决方案1】:

下面的代码对我有用。可能与您的操作方法有关。

@using (Html.BeginForm("About", "Home", FormMethod.Post, new { target = "_blank" })) 

正如您在评论中提到的,此方法返回 PDF 文件,您可以使用 window.open 喜欢:

window.open("../Document/SetCol", "_blank");

window.open("@Url.Action("LoadReport", "ExportReport")" + link, "_blank");

显然你必须定义一个点击事件处理程序。

【讨论】:

  • 有 VB 等价物吗?
猜你喜欢
  • 2016-08-14
  • 1970-01-01
  • 2017-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多