when i tried to use a pagination at the moment i start theproject. this error message appear " An exception of type 'System.NullReferenceException' occurred in App_Web_hqwgj1dl.dll but was not handled in user code ".
Can someone help me to fix it?
my controller is :
public class AccountController : Controller
{
// GET: Account
public ActionResult Index()
{
return View(this.GetAccounts(1));
}
[HttpPost]
public ActionResult Index(int currentPageIndex)
{
return View(this.GetAccounts(currentPageIndex));
}
private AccountModel GetAccounts(int currentPage)
{
int maxRows = 10;
using (GSAREntities entities = new GSAREntities())
{
AccountModel accountModel = new AccountModel();
accountModel.AccountTest = (from customer in entities.AccountTest1
select customer)
.OrderBy(customer => customer.AccountName)
.Skip((currentPage - 1) * maxRows)
.Take(maxRows).ToList();
double pageCount = (double)((decimal)entities.AccountTest1.Count() / Convert.ToDecimal(maxRows));
accountModel.PageCount = (int)Math.Ceiling(pageCount);
accountModel.CurrentPageIndex = currentPage;
return accountModel;
}
}
}