2013-04-09 66 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請求。