MVC View Button Click - Open in a new window or tab

Crystal Rouse
Crystal Rouse used Ask the Experts™
on
I have buttons using URL.Action and cannot get them to open in a new tab.  I've tried target=_blank with no luck!

 <button class="btn btn-info" style ="width:90px;" onclick="location.href='@Url.Action("LocationDetails", "Location", new
                                                                                                                 { id = @Model.id                                                                                                 
                                                                                                                 }
                                                                                         
                                )'">
                                Details
                            </button>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
<button /> tags don't have a target attribute, only <a /> tags  do. If you want to keep a button, then you'll need to use Javascript. However, since it appears that you're using Bootstrap, <a /> tags can be styled to look like buttons. You could do:

<a href="@Url.Action("LocationDetails", "Location", new { id = @Model.id })" class="btn btn-info" target="_blank">Details</a>

Open in new window


I advise against using a style attribute unless you really need to. Usually with Bootstrap you don't really need to. "Buttons" in Bootstrap will size to fit their text.
Crystal RouseTask Lead

Author

Commented:
Thanks!  I ended up using window.open but I'll this out as well!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial