Asp.net mvc paging assistant

I implemented a swap html helper (adapted from Stephen Sanderson's book). This is the current code:

public static string PageLinks (this is HtmlHelper html, int currentPage, int totalPages, Func pageUrl) {StringBuilder result = new StringBuilder ();

for (int i = 1; i <= totalPages; i++) { TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", pageUrl(i)); tag.InnerHtml = i.ToString(); if (i == currentPage) tag.AddCssClass("selectedPage"); result.AppendLine(tag.ToString()); } return result.ToString(); } 

This creates a bunch of links to every page of my elements. If there are many pages, this can be a bit overwhelming. I am looking for a similar implementation that produces something less overwhelming:

where 6 is the current page. I'm sure someone should have implemented something similar ... before I have to reuse the wheel.

Thanks.

Christian

+4
source share
2 answers
+2
source

I use this pager (also works with MVC2): http://blogs.taiga.nl/martijn/2008/08/27/paging-with-aspnet-mvc/

I found it really good.

+1
source

Source: https://habr.com/ru/post/1310457/


All Articles