asp.net-mvc url.Action 在 ASP.NET MVC 页面上的新窗口中打开链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2381949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
url.Action open link in new window on ASP.NET MVC Page
提问by Rita
I am trying open a new window using url.Action. And the new Window url is out of this current project(external website).
我正在尝试使用 url.Action 打开一个新窗口。并且新的 Window url 不在当前项目(外部网站)之外。
Here are two things i need to do:
这是我需要做的两件事:
- I need to open it in a new window.
- It is going to
http://localhost:57391/Home/http:/www.yahoo.cominstead of directly to Yahoo.
- 我需要在新窗口中打开它。
- 它将
http://localhost:57391/Home/http:/www.yahoo.com而不是直接到雅虎。
Here is my code:
这是我的代码:
<tr >
<td>
<a href="<%= Url.Action("http://www.yahoo.com") %>"><span>Go to Yahoo</span></a>
</td>
</tr>
回答by Richard Szalay
You don't need to use the helper methods at all:
您根本不需要使用辅助方法:
<a href="http://www.yahoo.com" target="_blank"><span>Go to Yahoo</span></a>
Html.Actionis only for controller actions, which an external link is not. There's nothing wrong with using plain HTML to link with.
Html.Action仅用于控制器操作,外部链接不是。使用纯 HTML 链接没有任何问题。
回答by Santan
You can try doing something like this
你可以尝试做这样的事情
<a href="http://@Model.Link" target="_blank"><span>@Model.Link</span></a>
<a href="http://@Model.Link" target="_blank"><span>@Model.Link</span></a>
回答by Raaghav
If the website parameter is dynamic -or- attaching from Model, we can try something like this.
如果网站参数是来自模型的动态 - 或 - 附加,我们可以尝试这样的事情。
<a href="@Model.Website" target="_blank">@Model.Website</a>

