public ActionResult EditProduct(int id) { User user = (User)Session["User"]; ShopManager shopMgr = new ShopManager(user); List<Category> cates = shopMgr.GetCategories(); List<Category> ccates = null; Product product = shopMgr.GetProduct(id); List<Image> images = shopMgr.GetProductImages(id); Category category = (from c in cates where c.ID == product.CategoryID select c).FirstOrDefault<Category>(); int pcid = 0; if (category.ParentID > 0) { pcid = (int)category.ParentID; ccates = (from c in cates where c.ParentID == category.ParentID select c).ToList<Category>(); } cates = (from c in cates where c.ParentID == 0 select c).ToList<Category>(); ViewData["cate"] = cates; ViewData["ccate"] = ccates; ViewData["images"] = images; ViewBag.pcid = pcid; return View(product); }