28

I want to embed a URL in an applet parameter.

The only way I know to create automatically the URL is Html.ActionLink(), but I want only the inner HREF attribute, not the whole link.

Is there another way to get what I wan't, other that using Regex on the output of ActionLink() to get the HREF attribute?

Tommy
  • 39,592
  • 10
  • 90
  • 121
user2173353
  • 4,316
  • 4
  • 47
  • 79

1 Answers1

51

To get only the URL, you can use Url.Action() instead of 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")
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
  • 2
    Additionally, Url.RouteUrl() will do the same thing, looking at the MSDN, it appears Url.RouteUrl() may be more universal, but it is unclear. Url.Action - Generates a fully qualified URL to an action. Url.RouteUrl - Generates a fully qualified URL (does not specify action). http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.routeurl(v=vs.108).aspx – Tommy Mar 28 '13 at 14:50
  • `Url.Action()` throws when the route cannot be mapped, `Html.ActionLink()` doesn't. – Professor of programming Apr 06 '15 at 12:25