tags:

views:

89

answers:

2

I have some code like this:

<a href="<%= Html.ActionLink(
   e.Member.UserName,
   "profile",
   "members",
   new {username = e.Member.UserName}, null) %>"/>

The links it generates look like this:

http://mywebsite.com/members/profile/?username=scottm

Is it possible to make the link this:

http://mywebsite.com/members/profile/scottm

without having to do this:

<a href="members/profile/<%= e.Member.UserName %>"><%= e.Member.UserName %></a>
+3  A: 

Yes, you just need to set up another route.

routes.maproute(
    "Profiles",
    "members/profile/{UserName},
    new { controller = "Members", Action = "Profile", UserName = "" }
}
Robert Harvey
Ahh, I also had to use HtmlHelper.RouteLink rather than ActionLink.
scottm
A: 

I think a route like this may work. Did you try it?

routes.MapRoute(
  "DefaultRest",                                              // Route name
  "members/profile/{username}",                           // URL with parameters
  new { controller = "Members", action = "Profile", UserName = "" }  // Parameter defaults
);
eKek0