asp.net-mvc ASP.NET MVC - 如何获取 URL 而不是操作链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15684797/
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
ASP.NET MVC - How to get an URL instead of an action link?
提问by user2173353
I want to embed a URL in an applet parameter.
我想在小程序参数中嵌入一个 URL。
The only way I know to create automatically the URL is Html.ActionLink(), but I want only the inner HREFattribute, not the whole link.
我知道自动创建 URL 的唯一方法是Html.ActionLink(),但我只想要内部HREF属性,而不是整个链接。
Is there another way to get what I wan't, other that using Regexon the output of ActionLink()to get the HREFattribute?
有没有另一种方法可以获得我想要的东西,而不是Regex在输出上使用ActionLink()来获取HREF属性?
回答by Christofer Eliasson
To get only the URL, you can use Url.Action()instead of Html.ActionLink().
要仅获取 URL,您可以使用Url.Action()代替Html.ActionLink()。
It has a number of overloads, so you can give it the name of a route, or the name of the action and the controller, or a number of other options.
它有很多重载,所以你可以给它一个路由的名字,或者动作和控制器的名字,或者一些其他的选项。
Example:
例子:
Url.Action("YourAction", "YourController")

