Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.ActionLink in asp.net MVC object value in wrong format

I have a html.actionlink that i wish to display a link to a members profile page like this: http://somesite.com/members/{username}

When use the following markup

<%= Html.ActionLink(r.MemberName, "profile", new { MemberName = r.MemberName } )%>

I get a link that looks like this: http://somesite.com/members?MemberName={username}

What would i need to change in the ActionLink helper to achieve a url like this:

http://somesite.com/members/{username}

like image 437
Jeremy Avatar asked Mar 01 '23 01:03

Jeremy


2 Answers

Assuming in your routes the username token is {username} like you show, try this:

<%= Html.ActionLink(r.MemberName, "profile", new { username = r.MemberName } )%>
like image 191
John Sheehan Avatar answered Mar 09 '23 00:03

John Sheehan


You should add the route that maps "/members/{MemberName}" before other routes in the routing table.

like image 36
mmx Avatar answered Mar 09 '23 00:03

mmx