Quote:
Originally Posted by Mr. Bill
in the following 'Inherits'
Code:
Inherits="System.Web.Mvc.ViewPage<NerdDinner.Helpers.PaginatedList<NerdDinner.Models.Dinner>>"
" NerdDinner.Helper..." is the name of the site/project/solution.
"NerdDinner. Helpers.Paginat..." is a folder in the solution.
"...Helpers .PaginatedList" is a .cs 'class' in the folder.
What is the correct way to use Paginated Lists as shown in the first section of the book. Please help.
|
Bill...
I have a problem within thew same chunk of code.
I have tried several ways, and although my solution compiles perfectly, when I invoke the index action method by sending a GET request in the browser (
http://localhost:1799/Dinners) I get a " Server Error in '/' Application. ".
The way I see (and try to deduce) the code is:
"Helpers" is a namespace within the "NerdDinner" namespace.
So I created the "Helpers" namespace and I created the PaginatedList class within PaginatedList.cs file inside the Helpers namespace:
namespace NerdDinner.Helpers
{
public class PaginatedList<T> : List<T>
{
//--- Propiedades ---//
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; }
public bool HasPreviousPage
{
get
{
return ( PageIndex > 0 );
}
}
public bool HasNextPage
{
get
{
return ( PageIndex + 1 < TotalPages );
}
}
//--- Methods ---//
public PaginatedList(IQueryable<T> fuente,
int indicePagina,
int tamanoPagina)
{
PageIndex = indicePagina;
PageSize = tamanoPagina;
//--- Query 1 ---//
TotalCount = fuente.Count( );
TotalPages = (int)Math.Ceiling( TotalCount / (double)PageSize );
//--- Query 2 ---//
this.AddRange( fuente.Skip( PageIndex * PageSize ).Take( PageSize ) );
}
}
}
Now it is up to you to create a folder called Helpers and include the Helpers namespace inside that folder.
Hope it helps in someway.
Carlos