MVC button will open in a new window

Hi I need to open my view in a new window on this button, but it opens in the same window. This is the syntax I am using.

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

      

Did I miss something? Thank.

+3


source to share


2 answers


Try window.open

to open the link in a new tab

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

      



DEMO

+3


source


As far as I know, <button>

won't work with target

. The same goes for the elements input type="button" ... />

:

You need to use an anchor and create it with css as a button



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

      

0


source







All Articles