/// <summary> /// 产品分类管理 /// </summary> /// <returns></returns> public ActionResult CategoryEdit(int? id) { var categories = new Swoopo.BLL.CategoryBll().GetAllToTree(); IList<CategoryEntity> items = new List<CategoryEntity>(); CategoryEntity c; foreach (var item in categories) { c = item.Clone(false) as CategoryEntity; c.CategoryName = AppCode.Tools.DeepBlank(c.Path, new char[] { ',' }) + " " + c.CategoryName; items.Add(c); } items.Insert(0, new CategoryEntity() { ID = 0, CategoryName = "做为父类" }); ViewData["Cateories"] = new SelectList(items, "ID", "CategoryName"); CategoryEntity category = new CategoryEntity(); if (id != null && id > 0) { category = new Swoopo.BLL.CategoryBll().GetById( new CategoryEntity { ID = Convert.ToInt32(id) }); ViewData["Cateories"] = new SelectList(items, "ID", "CategoryName", category.ParentID); } ViewData["categoryItem"] = category; return View(); }
private void getCategories() { var categories = new Swoopo.BLL.CategoryBll().GetAllToTree(); IList<CategoryEntity> items = new List<CategoryEntity>(); CategoryEntity c; foreach (var item in categories) { c = item.Clone(false) as CategoryEntity; c.CategoryName = AppCode.Tools.DeepBlank(c.Path, new char[] { ',' }) + " " + c.CategoryName; items.Add(c); } ViewData["Cateories"] = new SelectList(items, "ID", "CategoryName"); /* CategoryEntity category = new CategoryEntity(); if (id != null && id > 0) { category = new Swoopo.BLL.CategoryBll().GetById( new CategoryEntity { ID = Convert.ToInt32(id) }); ViewData["Cateories"] = new SelectList(items, "ID", "CategoryName", category.ParentID); } */ }