2010-03-04 390 views
5

我想使用url.Action打开一个新窗口。 而新的Window url已经不在这个当前的项目中(外部网站)。url.Action在ASP.NET MVC的新窗口中打开链接页面

这里有两件事情我需要做的:

  1. 我需要在新窗口中打开它。
  2. 这是去http://localhost:57391/Home/http:/www.yahoo.com而不是直接向雅虎。

这里是我的代码:

<tr > 
     <td>      
     <a href="<%= Url.Action("http://www.yahoo.com") %>"><span>Go to Yahoo</span></a> 
     </td> 
    </tr> 

回答

14

你不需要在所有使用的辅助方法:

<a href="http://www.yahoo.com" target="_blank"><span>Go to Yahoo</span></a> 

Html.Action仅用于控制器动作,其外部链接不。使用纯HTML进行链接没有任何问题。

-1

如果网站参数是动态的 - 或者从模型附加,我们可以尝试这样的事情。

<a href="@Model.Website" target="_blank">@Model.Website</a> 
+0

This solution goes to http://localhost:57391/Home/http:/www.yahoo.com. @santan's solution works "@Model.Link“ – NoloMokgosi 2017-06-18 18:50:47

1

你可以尝试做这样的事情

<a href="http://@Model.Link" target="_blank"><span>@Model.Link</span></a>

相关问题