如何在mvc 4中添加指向外部网站的链接? [英] How can I add links to external web sites in mvc 4?

查看:140
本文介绍了如何在mvc 4中添加指向外部网站的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的桌子上有一列外部网址。

我需要列出这些网站表。我做到了但我想要的是,当我点击此链接时,控件应该转移到新标签中的指定网站。





任何身体请帮助我..

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

推荐答案

将target =_ blank添加到您的锚标签。



它将打开新标签中的链接(如果禁用,则打开新窗口)





如果这有帮助,请花点时间接受解决方案。谢谢。
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.


在MVC中,没有用于基于绝对URL(即,到外部资源)生成链接的帮助器。但是如果你希望视图看起来很好用一致的帮助器格式,你就可以编写自己的帮助器。



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



例如:

创建扩展方法

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")


这篇关于如何在mvc 4中添加指向外部网站的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆