views:

23

answers:

1

I am using this custom route to enable paging in my index method in Home controller:

    routes.MapRoute( _
    "HomePage", _
    "Home/Index/{page_num}", _
    New With {.controller = "Home", .action = "Index", .page_num = ""} _
    )

But when I navigate to any page for example page 2, actionlinks append the page number to the url:

Html.ActionLink("Home", "Index", "Home")

will render _http://localhost/Home/Index/2 instead of _http://localhost/Home/Index

But I've noticed that action methods without parameters renders correctly: _http://localhost/Home/About

A: 

Html.ActionLink uses page_num parameter from previous route value dictionary unless you change some parameters left to page_num.

If you had the route like below:

routes.MapRoute( _
    "HomePage", _
    "{controller}/{action}/{page_num}", _
    New With {.controller = "Home", .action = "Index", .page_num = ""} _
    )

Html.ActionLink("Home","about") will clear page_num variable and you will get url like /home/about instead of /home/about/2. Look at this related Question. Maybe it would help.

Muhammad Adeel Zahid
I can't understand how this route is different from the previous one, but it will make actionlinks renders the correct url for other routes which have paging eg: _http://localhost/blog/index but still Html.ActionLink("Home", "Index", "Home") will add the page number as a parameter.
SilverDove