views:

126

answers:

2

I have a route definition like this:

routes.MapRoute(
    "Pagesize",
    "{controller}/{action}/pagesize/{pagesize}",
    new { controller = "Home", action = "Index", pagesize = 10 }
);

When I use

<%= Html.ActionLink("MyText", "myaction", new { pagesize = 10 }) %>

it renders as

<a href="/myaction/?pagesize=10">MyText</a>

I can understand I am misusing ActionLink since I have /pagesize/ in between. How can I correctly use it to create the link?

<a href="/myaction/pagesize/10">MyText</a>

Please note that I am using mvc RC2 and no other helper libraries. The generic ActionLink no longer exists in RC2.

A: 

have you tried specifying the defaults in the map route command

routes.MapRoute("Pagesize",
"{controller}/{action}/pagesize/{pagesize}",
new {pagesize = 10 },
new { controller = "Home", action = "Index" });
Richard
I am already setting the defaults with new { controller = "Home", action = "Index", pagesize = 10 }. Also tried your code but did not work.
Serhat Özgel
+2  A: 

Try:

<%= Html.RouteLink("MyText", "Pagesize", new { controller = "Home", action = "Index", pagesize = 10 })%>
Adam
Worked perfectly. Thanks.
Serhat Özgel