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.


source to share

2 answers


to open the link in a new tab

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





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




All Articles