Click here to Skip to main content
14,690,503 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I have table that contains a column of external website addresses.
I need to list those websites in a table. and I did it. But what I want is, when I click on this link, the control should be transfered to the specified website in a new tab.


any body please help me..
Posted

Add target="_blank" to your anchor tags.

It will open the link in new tab (or new window if that is disabled)


If this helps please take time to accept the solution. Thank you.
   
Comments
Jineesh TR 12-Jan-15 2:35am
   
Hi Sinisa,
When i click on the link it goes to new tab, but link prefixes the path of my website's current page from where the link is clicked. Can we avoid it or remove it
Sinisa Hajnal 12-Jan-15 3:48am
   
Don't use MVC helper, just put anchor tag and absolute link to it (you can put the link from the model - same for link text)
In MVC, there is no helpers for generating links based on absolute URLS (i.e., to external resources). But you can write your own helper for that if you want the view to look nice with the consistent Helper formatting.

http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs

example:
create extension method
public static class LinkHelper
{
	public static string ExternalLink(this HtmlHelper helper, string url, string text)
        {
        	return String.Format("<a href='http://{0}' target="_blank">{1}</a>", url, text);
	}
}


and call this in your view like:

@Html.ExternalLink("www.google.com", "Google")
   
v2
Comments
Jineesh TR 12-Jan-15 2:46am
   
I searched there but I didnt get an answer. Can you please provide me some more data..
[no name] 12-Jan-15 3:32am
   
@jineesh, Please check the answer, I updated the with code.
Jineesh TR 12-Jan-15 4:00am
   
thanks a lot abhinav.. It really worked fine for me..
[no name] 12-Jan-15 5:41am
   
welcome Jineesh
JAPANDUHOC 9-Oct-20 0:41am
   
thanks you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900