Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC ActionLink with LinkText = absolute URL

<%: Html.ActionLink("Share Me", "Index", "Mall", new { username = Model.Username }, null)%>

results as expected according to mapped routes:

<a href="/Mall/Username">Share Me</a>

I however need it to not say Share Me but to show the absolute URL, as well as use the absolute URL as the href:

<a href="http://www.url.com/Mall/Username">http://www.url.com/Mall/Username</a>

I feel this isn't a hard task, but being very green in tackling MVC I'm having a hard time figuring it out.

like image 272
Nick Spiers Avatar asked Sep 23 '10 14:09

Nick Spiers


1 Answers

Rather than using Html.ActionLink, you should have a look at Url.RouteUrl (which ActionLink uses internally anyway). Something like...

<% var myUrl = Url.RouteUrl("Default", new { action = "Mall", username = Model.Username }, Request.Url.Scheme).ToString() %>

<a href="<%:myUrl%>"><%:myUrl%></a>

Note the first parameter is the route name.

like image 141
Clicktricity Avatar answered Oct 09 '22 13:10

Clicktricity