Serhat Ozgel
Serhat Ozgel

Reputation: 23766

Html.ActionLink for non-standard routing

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.

Upvotes: 0

Views: 988

Answers (2)

Adam
Adam

Reputation: 2004

Try:

<%= Html.RouteLink("MyText", "Pagesize", new { controller = "Home", action = "Index", pagesize = 10 })%>

Upvotes: 4

Richard
Richard

Reputation: 22016

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" });

Upvotes: 0

Related Questions