@@ -43,36 +43,51 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
4343 tag . InnerHtml . AppendHtml ( previousPage ) ;
4444 }
4545
46+ CreateMiddlePages ( urlHelper , tag ) ;
47+
48+ if ( PagingInformation . HasNextPage )
49+ {
50+ TagBuilder nextPage = CreateTag ( PagingInformation . CurrentPage + 1 , urlHelper , "Next" ) ;
51+ TagBuilder lastPage = CreateTag ( PagingInformation . TotalPages , urlHelper , "Last Page" ) ;
52+ tag . InnerHtml . AppendHtml ( nextPage ) ;
53+ tag . InnerHtml . AppendHtml ( lastPage ) ;
54+ }
55+
56+ output . Content . AppendHtml ( tag ) ;
57+ }
58+
59+ private void CreateMiddlePages ( IUrlHelper urlHelper , TagBuilder tag )
60+ {
4661 if ( PagingInformation . TotalPages <= 6 )
4762 {
4863 CreatePagination ( tag , urlHelper , 1 , PagingInformation . TotalPages ) ;
4964 }
5065 else if ( PagingInformation . TotalPages > 6 )
5166 {
67+ int leftPages = PagingInformation . TotalPages - PagingInformation . CurrentPage ;
68+
5269 if ( PagingInformation . CurrentPage <= 3 )
70+ {
5371 CreatePagination ( tag , urlHelper , 1 , 3 ) ;
72+ }
5473 else if ( PagingInformation . CurrentPage > 3 )
74+ {
5575 CreatePagination ( tag , urlHelper , PagingInformation . CurrentPage - 3 , PagingInformation . CurrentPage ) ;
76+ }
5677
57- int leftPages = PagingInformation . TotalPages - PagingInformation . CurrentPage ;
58-
59- if ( leftPages > 0 && leftPages <= 2 )
60- CreatePagination ( tag , urlHelper , PagingInformation . CurrentPage + 1 , PagingInformation . CurrentPage + leftPages ) ;
61- else if ( PagingInformation . CurrentPage <= 3 )
78+ if ( PagingInformation . CurrentPage <= 3 )
79+ {
6280 CreatePagination ( tag , urlHelper , PagingInformation . TotalPages - 2 , PagingInformation . TotalPages ) ;
81+ }
82+ else if ( leftPages > 0 && leftPages <= 2 )
83+ {
84+ CreatePagination ( tag , urlHelper , PagingInformation . CurrentPage + 1 , PagingInformation . CurrentPage + leftPages ) ;
85+ }
6386 else if ( leftPages > 0 )
87+ {
6488 CreatePagination ( tag , urlHelper , PagingInformation . CurrentPage + 1 , PagingInformation . CurrentPage + 3 ) ;
89+ }
6590 }
66-
67- if ( PagingInformation . HasNextPage )
68- {
69- TagBuilder nextPage = CreateTag ( PagingInformation . CurrentPage + 1 , urlHelper , "Next" ) ;
70- TagBuilder lastPage = CreateTag ( PagingInformation . TotalPages , urlHelper , "Last Page" ) ;
71- tag . InnerHtml . AppendHtml ( nextPage ) ;
72- tag . InnerHtml . AppendHtml ( lastPage ) ;
73- }
74-
75- output . Content . AppendHtml ( tag ) ;
7691 }
7792
7893 private void CreatePagination ( TagBuilder tag , IUrlHelper urlHelper , int start , int end )
0 commit comments