Reputation: 5
I was made paging system. Everything is OK. After click 2nd page all homepage links changing.
@Html.ActionLink("Home page", "Index", "Home") //This is standard routing without values.
I was added paging links to end of page.
@Html.ActionLink("2", "Index", "Home", New With {.id = 2}, Nothing) //This works good too.
My problem is when I click to 2nd or more page (e.g : www.site.com/Home/Index/2) my all homepage links converting to
<a href="/Home/Index/2">Home page</a>
same this. How I can resolve this problem?
Upvotes: 0
Views: 2015
Reputation: 139778
When you click on the 2nd page the {.id = 2}
will be part of your RouteData. And because your routing probably looks like this: (in Gloabal.asax)
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
ASP.NET MVC will use this route for the generated links. So it will include Id = 2. To fix this you need to explicitly override it when it's not needed:
@Html.ActionLink("Home page", "Index", "Home", New With {.id = ""}, Nothing)
Upvotes: 3