// GET: Product public ActionResult ByCat(int?id, int curPage = 1) { if (id.HasValue == false) { return(RedirectToAction("Index", "Home")); } using (QLBHLapTopEntities ctx = new QLBHLapTopEntities()) { //List<Product> list = ctx.Products // .Where(p => p.ManufacturerID == id).ToList(); var query = ctx.Products.Where(p => p.ManufacturerID == id); int n = query.Count(); int nPages = n / 3; if (n % 3 > 0) { nPages++; } ViewBag.Pages = nPages; ViewBag.NextPage = curPage + 1; ViewBag.PrevPage = curPage - 1; int nSkip = (curPage - 1) * 3; List <Product> list = query .OrderBy(p => p.ProID) .Skip(nSkip).Take(3) .ToList(); return(View(list)); } }
// GET: Manufacturer public ActionResult PartialView() { using (QLBHLapTopEntities ctx = new QLBHLapTopEntities()) { var list = ctx.Manufacturers.ToList(); return(PartialView(list)); } }