views:

4300

answers:

6

No javascript/AJAX to be used.

when clicked on the hyperlink, it should open a new browser window.

+12  A: 

Basic HTML Anchor Element:

<a href="http://www.w3schools.com/"
target="_blank">Visit W3Schools!</a>

ASP.NET WebForms HyperLink Element:

<asp:HyperLink ID="HyperLink1" runat="server" Target="_blank">HyperLink</asp:HyperLink>

ASP.NET MVC Style:

<%= Html.ActionLink<HomeController>(c => c.Index(), "Click me", new { target = "_blank" }) %>

All three open a new tab, would that suit your needs?

Shaharyar
This is true but I just wanted to add you do not want to use the asp:hyperlink in asp.net mvc see the below answer by James S.
David
Of course, it can be done with the Html.ActionLink item too. - altered my comment to match it.
Shaharyar
+3  A: 
<A Href="page.html" target="_blank">Link text </A>

The target="_blank" is the specific part you need.

Alternatively you could use target="new". Here's an article that describes how the two behave differently.

Josh W.
+4  A: 

If you're not using javascript, you need to use the target="_blank". But to do it in a cleaner mvc fashion, do:

<%= Html.ActionLink("Click me", "ActionName", null, new {target="_blank"}) %>
James S
Just how is that cleaner than the following<a href="ActionName" target="_blank">Click Me</a>
Cyril Gupta
It's a little weird but it's the asp.net mvc way, and you can do things create your own helpers etc., also you can easily put in the view vars here, instead of hard coding the strings.
David
Yes. It's weird. And, no, it's not cleaner. However, ActionLink "knows" about your routes. So if your routes change, then the link gets updated. Also, after you've put your view vars in there, it'll keep track of variable names, so refactoring is easier, and also strip out parameters with null values (which is pretty cool). If you strongly type it, it's even better for compile-time checking, but it's a bit funkier looking (<%= Html.ActionLink<ClickController>(c => c.Action(var1, null, var3), "Click Me", new {target="_blank"}); %>).
James S
Oh. And visual studio has problems with variable names in quotes in HTML, so it won't autocomplete on something like <a href="<%= c.ID %>"...>. I used to hardcode all my hrefs manually, but I've switched to strongly typed.
James S
+2  A: 

If your question is - How can I create pop-up window in asp.net mvc

The simple answer is : can't

For that matter you can't in PHP, JSP or any other server side scripting language.

You noticed that the solutions above are all HTML?

The pop-up window is a domain that has to be handled client side. The server languages can spew HTML/Javsascript that have the commands to open a pop-up window. They intrinsically can't order the browser to open a window.

Cyril Gupta
A: 

a new browser window is not a popup

Omu
-1 : This is not a helpful answer, its just a snide remark. Its pretty clear what he was asking for. If you really feel compelled to snipe at a questions wording then a more appropriate place to do so would be the comments.
Sailing Judo
A: 

<%= Html.ActionLink("Click me", "ActionName", null, new {target="_blank"}) %>

The Html.ActionLink approach seems to only open a new instance of the website in a new browser.

Is there any way to open a specific view in a new browser? For example a report.

Doug Kimzey