ryanzec
ryanzec

Reputation: 28040

Generate Full URL ASP.NET MVC Razor Views

I am trying to generate the full URL for a route link in my razor view for ASP.NET MVC 3. I know I can use Html.RouteLink to generate a link however all I want is the URL, not the surrounding a tag wrapper. Is there a way to do this?

Upvotes: 23

Views: 24537

Answers (3)

balexandre
balexandre

Reputation: 75073

Are you talking about:

<a href="@Url.Action("Action", "Controller", new { @id = "2" })">
    Link to Page</a>

vs.

@Html.ActionLink("Link to page", "Action", "Controller", new { @id = "2" })

The Url Model builds only Links; Html builds the HTML as well.

Upvotes: 24

GvS
GvS

Reputation: 52518

Use RouteUrl as tvanfosson proposes.

I would just want to mention T4MVC adds the extension ActionAbsolute to create a full url from an action.

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532435

Use the UrlHelper.

 Url.RouteUrl( "MyRoute" )

Upvotes: 19

Related Questions