2013-04-09 78 views
0

这是我的仓库层:寻呼与PagedList

public List<Section> GetAllSections() 
{ 
    return context.Sections.Include("Groups").Include("Groups.Classes").ToList(); 
} 

这是我的应用层:

public List<Section> GetAllSections() 
{ 
    return cacheSectionRepo.GetAllSections(); 
} 

而且在控制我有:

SectionApplication sectionApp = new SectionApplication(); 
public ActionResult Index() 
{ 
    return View(sectionApp.GetAllSections()); 
} 

现在,我想使我的Index查看paged.I想使用PagedList.How应该这样做吗?例如,我想让每个页面显示5条记录。

回答

1

你可以通过页面数量和页面大小到存储库层,然后用SkipTake Linq的语句来筛选出您需要的行:

public List<Section> GetAllSections(int pageSize=5, int pageNo) 
{ 
    return cacheSectionRepo.GetAllSections().Skip(pageSize * pageNo).Take(pageSize);; 
} 

另外,您可以在您执行滤波仓库层。然后,对控制器发出的每一个请求,你都会发送pageNo给控制器,最好通过AJAX请求。