Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var editedCategory = productCategoryDAO.Get(id);

            var categories = productCategoryDAO.GetAll();

            //parent selectlist
            var parentSelectList = new MySelectList()
            {
                FormElementName = "ParentId"
            };

            parentSelectList.Items.Add(new MySelectListItem()
            {
                Id   = "",
                Name = "Chọn danh mục cha"
            });
            foreach (var item in categories)
            {
                if (item.Id == editedCategory.ParentId)
                {
                    parentSelectList.SelectedItems.Add(item.Id.ToString());
                }

                parentSelectList.Items.Add(new MySelectListItem()
                {
                    Id   = item.Id.ToString(),
                    Name = item.Name
                });
            }

            ViewBag.Parents         = parentSelectList;
            ViewBag.OtherCategories = productCategoryDAO.GetAllExcept(id).ToList();
            return(View(editedCategory));
        }