I have a customized version of nopCommerce where on the customers.ascx control in the administration / modules folder I use the Common.PagedList<T>(...) function to get a new paged list of customers, which isn't standard, but that's why I came across this.
Your paged list is currently as follows:
/// <summary>
/// Paged list
/// </summary>
/// <typeparam name="T">T</typeparam>
public class PagedList<T> : List<T>, IPagedList
{
/// <summary>
/// Ctor
/// </summary>
/// <param name="source">source</param>
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
public PagedList(IQueryable<T> source, int pageIndex, int pageSize)
{
int total = source.Count();
this.TotalCount = total;
this.TotalPages = total / pageSize;
if (total % pageSize > 0)
TotalPages++;
this.PageSize = pageSize;
this.PageIndex = pageIndex;
this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());
}
/// <summary>
/// Ctor
/// </summary>
/// <param name="source">source</param>
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
public PagedList(List<T> source, int pageIndex, int pageSize)
{
TotalCount = source.Count();
TotalPages = TotalCount / PageSize;
if (TotalCount % pageSize > 0)
TotalPages++;
this.PageSize = pageSize;
this.PageIndex = pageIndex;
this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());
}
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); }
}
}
In the second function, the one that takes in a List of type T instead of the IQueryable of type T, the public properties are used before values are set for them. On an unmodified 1.9 release, this is line 40-45. Because these properties do not have values set for them, when you call this function, instead of having the page size set to the value passed in, it uses a default of zero, which causes the following exception to be thrown:
Attempted to divide by zero.
This exception is caught by the admin area properly, but the code for the second function should be changed (for lines 40-45) to match lines 20-25 from the IQueryable function that properly sets the properties before calling them...so basically the second function would look like:
/// <summary>
/// Ctor
/// </summary>
/// <param name="source">source</param>
/// <param name="pageIndex">Page index</param>
/// <param name="pageSize">Page size</param>
public PagedList(List<T> source, int pageIndex, int pageSize)
{
int total = source.Count();
this.TotalCount = total;
this.TotalPages = total / pageSize;
if (total % pageSize > 0)
TotalPages++;
this.PageSize = pageSize;
this.PageIndex = pageIndex;
this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList());
}
after modifications. I tested and confirmed that this does fix the problem.
Edit: Sorry, forgot to mention that this is for version 1.90 of nopCommerce.
Thanks