views:

57

answers:

1
<%: 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"&gt;http://www.url.com/Mall/Username&lt;/a&gt;

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

A: 

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.

Clicktricity
Exactly what I was looking for, thanks!
Nick Spiers

related questions