martijnboland / MvcPaging

ASP.NET MVC Paging HTML helper
https://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/
MIT License
290 stars 144 forks source link

Are pretty URLs possible? #62

Closed Ciwan1859 closed 6 years ago

Ciwan1859 commented 7 years ago

Hi

I have integrated your code and paging works, but the URLs are not pretty URLs. What I would like them to be is:

http://www.mysite.com/suppliers/page/1 http://www.mysite.com/suppliers/page/2

And so on. Is this possible? Right now I'm getting:

http://www.mysite.com/suppliers/page?page=2

Any help would be greatly appreciated.

martijnboland commented 7 years ago

Yes, this is possible with custom routes. See http://demo.taiga.nl/mvcpaging/SimplePaging. The route configuration for this page is:

routes.MapRoute("SimplePaging", "SimplePaging/{page}",
                new { controller = "Paging", action = "Index", page = UrlParameter.Optional }); 

For the scenario above, you could probably use something like:

routes.MapRoute("DefaultPaged",  "{controller}/{action}/page/{page}", 
                new { controller = "Home", action = "Index", page = 1 },  // Parameter defaults