如何正确地连接在MVC剃刀code链接到外部URL [英] How to properly encode links to external URL in MVC Razor

查看:156
本文介绍了如何正确地连接在MVC剃刀code链接到外部URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此观点假设显示超链接的列表,每个指向外部U​​RL。我们的目标是为用户点击这些链接之一,并有自己的浏览器中打开一个新的标签与选定的URL。
目前,我有以下标记:

This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL. Currently I have the following markup:

@Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")

此标记生成:

http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite

而不是:

http://subdomain.mydomain.com/SomeSite

我可以在我的标记改变,使这项工作,我期待?

What can I change in my markup to make this work as I expect?

推荐答案

您不需要使用 @ Html.ActionLink 为。只需使用一个普通的标记:

You don't need to use @Html.ActionLink for that. Just use a plain A tag:

<a href="http://subdomain.mydomain.com/SomeSite">SomeSite</a>

Html.ActionLink 是专门用于生成链接到MVC控制器定义的操作,在相同的应用程序的。既然你链接到一个绝对的URL,你不需要任何的那 Html.ActionLink 提供的功能。

Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.

这篇关于如何正确地连接在MVC剃刀code链接到外部URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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