【问题标题】:MVC Button click open in new WindowMVC 按钮单击在新窗口中打开
【发布时间】:2014-10-15 15:50:10
【问题描述】:

您好,我需要在单击此按钮时在新窗口中打开视图,但它会在同一窗口中打开。这是我正在使用的语法。

<button  id="btnPrintReport" onclick="location.href='@Url.Action("LoadReports", "DashBoard", new { target="_blank" })'" >Print</button>

我错过了什么吗?谢谢。

【问题讨论】:

    标签: asp.net-mvc razor


    【解决方案1】:

    尝试window.open在新标签页中打开链接

    onclick="window.open('@Url.Action("LoadReports", "DashBoard", new { target="_blank" })')"
    

    DEMO

    【讨论】:

    • 我只想在按下键盘控制按钮和鼠标点击时打开新标签页提前谢谢
    • 先生,此代码始终在新选项卡中打开窗口我的要求是在按下鼠标单击的同时按下控制按钮时打开选项卡。
    • 在这种情况下,您必须在其上方放置一个相同的条件
    • 目标 URL 参数 (target = "_blank") 似乎不是必需的。
    【解决方案2】:

    据我所知,&lt;button&gt; 不适用于 targetinput type="button" ... /&gt; 元素也是如此:

    您需要使用一个锚点,并使用 css 作为按钮对其进行样式化

    <a href=@Url.Action("LoadReports", "DashBoard") id="aPrintReport" target="_blank" class="button">Print</a>
    
    <!--taken from http://stackoverflow.com/questions/2187008/styling-an-anchor-tag-to-look-like-a-submit-button-->
    .button {
        text-decoration: none; font: menu;
        display: inline-block; padding: 2px 8px;
        background: ButtonFace; color: ButtonText;
        border-style: solid; border-width: 2px;
        border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
    }
    .button:active {
        border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
    }
    

    【讨论】:

    • 嗨,如果操作是表单后操作,需要进行哪些更改? AFAIK Url.Action 仅是 GET。
    猜你喜欢
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多