This project is read-only.

Frienly url's by @html.ActionLink?

Topics: Writing modules
Jun 22, 2011 at 8:18 PM

I'm trying to build actionLinks with nice urls' but it returns only url's in the following format:

Does anyone knows an solution so that the ouput becomes:



Jun 22, 2011 at 8:53 PM

You have to implement IRouteProvider and define the routing for your controller/action there.

Jun 22, 2011 at 9:14 PM

I already did that but didn't help. The page/action is accesible by this route though

Jun 22, 2011 at 10:22 PM

It's probably a matter of route priority. Matching your route works, but when MVC tries to revert the logic to generate the url, it finds another route before yours. We so need route debugging...

Jun 23, 2011 at 6:52 PM

Ok thanks. Already thought it had to be something like a route priority/order problem. But i still got the error though a tried all kinds of priorities.


Jun 23, 2011 at 7:25 PM

oooh, I get it. Remove the Route part from that content type.

Jun 23, 2011 at 7:55 PM

Nope it didn't fixed it. But it changed the url for the page where the ActionLink is placed. Instead of nice url the url of that page becomes:


Maybe it has something to do with the fact that the ActionLink is just a virtual page and it has no contentPart?

Jun 23, 2011 at 8:35 PM

What does your action link look like?

Jun 23, 2011 at 9:02 PM
@Html.ActionLink(@player.Fullname, "Index""Player"new { userId = @player.Fullname, fullname = @player.Fullname })

Jun 23, 2011 at 9:22 PM

And how is your route declared? (you might want to specify the area in that action link).

Jun 24, 2011 at 7:39 AM

What I usually do is use RouteUrl with the route name I declared. Or, how bertrandleroy suggested in new{ userId= ... specify , area = "YourModuleName}. Or whatever you defined as an area when you set up the RouteProvider's routes.

I usually like to have Routes.NameOfTheRoute as a static or constant in my Routes.cs file. That way I always know which route I want to display. It's just something that happens in projects with a lot of MvcAreas.

Jun 25, 2011 at 2:19 PM

Ok guys i fixed it :)I changed the actionlink from :

@Html.ActionLink(@player.Fullname, "Index""Player"new { userId = @player.Fullname, fullname = @player.Fullname })
Html.ActionLink(@player.Fullname, "Index"new { userId = @player.Fullname, fullname = @player.Fullname, controller = "Player" ,area = "myareaname" })

So basicly the problem was the way i built up the actionlink.
Thanks you guys for the help! Keep up the good work!