我从 NuGet ( https://github.com/martijnboland/MvcPaging )安装了 MVCPaging
我想在我的记录集上启用搜索/过滤器以及分页,所以这就是我想出的:
public ActionResult Index(string str, int? page)
{
int pageSize = page.HasValue ? page.Value - 1 : 0;
// Get initial recordset
var items = db.Customers.OrderByDescending(a => a.OfferCreatedOn).Include(a => a.Offers);
// check if searchstring has any value, and filter if so
if (!string.IsNullOrWhiteSpace(str))
{
items = items.Where(t => (t.CustomerName.ToLower().IndexOf(str.ToLower()) > -1)
|| (t.OfferReference.ToLower().IndexOf(str.ToLower()) > -1)
|| (t.EmailAddress.ToLower().IndexOf(str.ToLower()) > -1)
);
}
// Pass remaining list to the pager
//
// Error on the next line
//
items = items.OrderByDescending(a => a.OfferCreatedOn)
.ToPagedList(page ?? 0, pageSize);
return View(items);
}
但是,我在最后一行遇到错误:
Cannot implicitly convert type 'MvcPaging.IPagedList<FGBS.Models.Customer>' to 'System.Linq.IQueryable<FGBS.Models.Customer>'. An explicit conversion exists (are you missing a cast?)
谁能看到我做错了什么?
谢谢你,马克