public ActionResult ListOfItems(int Page = 1) { ItemView dataForView = new ItemView(); dataForView.ItemsPerRow = 5; dataForView.Paging = new ForPaging(Page); dataForView.IdList = itemService.GetIdList(dataForView.Paging); //怎麼塞ItemDetailView資料? dataForView.ItemBlock = new List<ItemDetailView>(); //注意進位問題 dataForView.RowsForItemsDisplay = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(dataForView.IdList.Count) / dataForView.ItemsPerRow)); foreach (var id in dataForView.IdList) { ItemDetailView newItemBlock = new ItemDetailView(); newItemBlock.Record = itemService.GetItemById(id); string cart = (HttpContext.Session["Cart"] != null) ? HttpContext.Session["Cart"].ToString() : null; newItemBlock.IsInCart = cartService.IsItemInCart(cart, id); dataForView.ItemBlock.Add(newItemBlock); } return View(dataForView); }
public ActionResult ItemBlock(int id) { ItemDetailView dataForView = new ItemDetailView(); dataForView.Record = itemService.GetItemById(id); string cart = (HttpContext.Session["Cart"] != null) ? HttpContext.Session["Cart"].ToString() : null; dataForView.IsInCart = cartService.IsItemInCart(cart, id); return PartialView(dataForView); }