Any page navigation helpers for ASP.NET MVC?

Are there any html helpers for navigating pages? eg. if I have 1000 entries to display, I want to display the previous 1 2 3 4 ... etc. The following link is in the filtered collection section.

Does anyone know anything there?

+6
asp.net-mvc navigation
source share
4 answers
+1
source share

If you are creating a data table from JSON data, I highly recommend the DataTable YUI component (Yahoo UI Library) ( http://developer.yahoo.com/yui/datatable/ ). It works very well, and you have the opportunity to return the entire set of records in order to start from it, and then perform swapping through all client sides or return the downloaded set from the server.

This probably doesn't fit your scenario, but just thought I'd say that.

+3
source share

I have a swap grid in Dynamic Data for an MVC example application , but the grid is displayed manually. The data uses the PagedList, which came from Rob Conery (which, in turn, I got it from ScottGu).

I was thinking about how paging helper for MVC could be useful ...

0
source share

What I did for paging at the moment is to create a Pager control. To update, I need a paging URL, html element identifier, page number, page size and total.

The paging URL is in the form of a controller / action in which the action returns an html string (display data page)

The pager adds a list of javascript links for pages. These links invoke the jQuery-based ajax function, which hits the paging URL. Each click on the page replaces the current content of the html element with the results of the ajax call. Something like that:

public string Render() { var buffer = new StringBuilder( 1000 ); buffer.AppendLine( @"<ul class=""datatable_pager"">" ) .AppendLine( "\t<li>Additional Pages:</li>" ); int numberOfPages = TotalItemCount % PageSize == 0 ? TotalItemCount / PageSize : TotalItemCount / PageSize + 1; for( int i = 0; i < numberOfPages; i++ ) { AppendPageLink( buffer, i ); } buffer.AppendLine( "\t</ul>" ); AppendPagingJS( buffer ); return buffer.ToString( ); } private void AppendPageLink( StringBuilder buffer, int i ) { buffer.Append( "\t\t<li><a href=\"" ) .Append( PagingLink.Replace( "$PAGE$", i.ToString( ) ) ) .Append( "\">" ) .Append( i.ToString( ) ) .Append( "</a>" ) .AppendLine( "\t\t</li>" ); } private void AppendPagingJS( StringBuilder buffer ) { buffer.AppendLine( @" <script type=""text/javascript""> function page( page, size, updateElement ) { $.post( '" + PagingUrl + @"', { pageNumber: page, pageSize: size, }, function(response) { $(""#"" + updateElement).html(response); }, ""html"" ); } </script>" ); } 

Javascript messages to the paging url, so to do this you need to do the following:

int.TryParse (Request.Params ["pageNumber"], out page) int.TryParse (Request.Params ["pageSize"], size out))

and use the results with your data access components to grab the data page, make it as html and return it.

Hope this helps, I can expand it if necessary.

0
source share

All Articles