MVC Html.ActionLink not passing querystring properly
Posted
by Dave Hanna
on Stack Overflow
See other posts from Stack Overflow
or by Dave Hanna
Published on 2010-04-09T21:14:26Z
Indexed on
2010/04/09
21:23 UTC
Read the original article
Hit count: 1592
This seems like it should be pretty straight forward, but I'm apparently confused.
I have a List view that displays a paged list. At the bottom I have a set of actionlinks:
<%= Html.ActionLink("First Page", "List", new { page = 1} ) %>
<%= Html.ActionLink("Prev Page", "List", new { page = Model.PageNumber - 1 }) %>
<%= Html.ActionLink("Next Page", "List", new { page = Model.PageNumber + 1 }) %>
<%= Html.ActionLink("Last Page", "List", new { page = Model.LastPage } )%>
I'm using the basic default routes setup, except with "List" substituted for "Index":
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
The problem is that the ActionLink helpers are generating links of the form:
http://localhost:2083/Retrofit?page=2
rather than
http://localhost:2083/Retrofit/?page=2
(with the trailing slash after the controller name & before the query string). When the first URL is routed, it completely loses the query string - if I look at Request.QueryString by the time it gets to the controller, it's null. If I enter the second URL (with the trailing slash), it comes in properly (i.e., QueryString of "page=2").
So how can I either get the ActionLink helper to generate the right URL, or get the Routing to properly parse what ActionLink is generating?
Thanks.
© Stack Overflow or respective owner