public ViewResult LoadList() { int page_Size = 20; List <Product> ProList = dao.GetAllProduct(); string current_P = Request["page"]; if (current_P == null) { current_P = "1"; } if (!System.Text.RegularExpressions.Regex.IsMatch(current_P, "[0-9]{1,5}")) { current_P = "1"; } if (current_P.Equals("0")) { current_P = "1"; } int totalRecord = ProList.Count; int total_Page = 1; if (totalRecord % page_Size == 0) { total_Page = totalRecord / page_Size; } else { total_Page = (totalRecord / page_Size) + 1; } if (int.Parse(current_P) > total_Page) { current_P = "1"; } int current_Page = int.Parse(current_P); List <Product> current_List = new List <Product>(); for (int i = (current_Page - 1) * page_Size; i < (current_Page * page_Size); i++) { if (i == totalRecord) { break; } else { current_List.Add(ProList[i]); } } var model = current_List; List <Brand> brand = dao_Brand.GetAllBrands(); Session["Brand"] = brand; List <Category> category = dao_Category.GetAllCategories(); Session["Category"] = category; Session["Page"] = total_Page; return(View("LoadList", model)); }