Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 525
ryanzec Avatar asked Jun 10 '11 12:06

ryanzec


3 Answers

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.

like image 67
balexandre Avatar answered Nov 13 '22 13:11

balexandre


Use the UrlHelper.

 Url.RouteUrl( "MyRoute" )
like image 19
tvanfosson Avatar answered Nov 13 '22 13:11

tvanfosson


Use RouteUrl as tvanfosson proposes.

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

like image 1
GvS Avatar answered Nov 13 '22 15:11

GvS