Esempio n. 1
0
        public JsonResult ChildrenCategories(int IDParent, string IDChilrenCategories)
        {
            var list = new CategoryModel().GetAll().Where(x => x.IDParent == IDParent);

            string[] listSelectCategories = null;
            if (IDChilrenCategories != "NaN")
            {
                listSelectCategories = IDChilrenCategories.Split(',');
            }

            var listIDCategories = new List <int>();

            if (listSelectCategories != null)
            {
                foreach (var item in listSelectCategories)
                {
                    listIDCategories.Add(Int32.Parse(item));
                }
            }

            var listDrop = new List <DropListItem>();

            list.ForEach(item => listDrop.Add(new DropListItem(item.Name, item.ID.GetValueOrDefault(0), listIDCategories.Exists(item1 => item1 == item.ID))));
            return(Json(new
            {
                list = new JavaScriptSerializer().Serialize(listDrop)
            }));
        }