tags:

views:

68

answers:

2

Hello

I have a problem with getting my pager-function to work. For some reason it doesnt like when I try to pass the current pageindex +1 to the same page for it to display next one.

<% if (Model.Users.HasNextPage) { %>

    <%= Html.RouteLink(">>>", "Users", new { page = (Model.Users.PageIndex +1) })%>

    <% } %>

If I only use: ”>>>”, ”Users) it works, although the next page function doesn’t work since it doesn’t assign next value.

If I debug Model.Users.PageIndex it has the value 0 when it loads the page (which it should have).

Somehow it doesn’t like the “new”-thingy at the end

I have swedish errors on, but it complains something about not finding the path/route/reference to the location of User, or how its set.

The actionresult looks like:

    public ActionResult Users(int? page){
        const int pagesize = 10;

        var pagnatedUsers = new PaginatedList<User>(_us.GetUsers(), page ?? 0, pagesize);

        return View("Users", new UserAdminEditViewModel { Users = pagnatedUsers });
    }

Thanks in advance /M

+1  A: 

I'm going to guess "Users" in your second parameter to Html.RouteLink is supposed to refer to your controller action name. RouteLink actually doesn't have an overload of (string linkText, string actionName, object routeValues) which is what it appears you are trying to provide.

The overload you are calling is actually asking for the routeName in the second parameter, and you don't have such a route defined!

Try this

Html.RouteLink(">>>", new { controller="Home", action="Users", page = (Model.Users.PageIndex +1) })%>

substituting for your actual controller name.


Update/response: I was trying to explain why your code wasn't working as expected. Indeed, if you use ActionLink instead with your original parameters that is also a solution - and probably the better one since it seems to be what you want.

RouteLink and ActionLink are essentially the same under the covers (they both end up calling the same underlying code that actually generates the link). The difference is only in context of use - RouteLink is there to help you generate links based on your routing configuration (eg. by a route name) and ActionLink is there for links based on your controller actions (eg. by an action name). And there is plenty of overlap where you could use both of them in the exact same way.

Kurt Schindler
A: 

I got that RouteLink code from the Nerddinner-example. And now when I changed to ActionLink instead of RouteLink it worked.

Not quite sure what the difference is between having ActionLink or the way Kurt describes.

molgan
see my updated answer regarding RouteLink and ActionLink
Kurt Schindler