Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paging helper asp.net mvc

I have implemented a paging html helper (adapted from steven sanderson's book). This is the current code:

public static string PageLinks(this 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 produces a bunch of links to each page of my items. If there are many pages this can be a bit overwhelming. I am looking for a similar implementation which produces something less overwhelming like this:

where 6 is the current page. I am sure someone must have implemented something similar ... before I have to re-implement the wheel.

Thanks.

Christian

like image 602
cs0815 Avatar asked Nov 05 '22 13:11

cs0815


1 Answers

There's a pager helper in MVCContrib.

like image 185
Darin Dimitrov Avatar answered Nov 12 '22 18:11

Darin Dimitrov