示例#1
0
        public ActionResult Index()
        {
            IList<Category> sysCategoryList = CategoryManager.GetSysCategory();
            if (sysCategoryList == null || sysCategoryList.Count == 0)
            {
                sysCategoryList = new List<Category>();
                Category category1 = new Category() { IsSystem = true, MenuPriority = 0, MenuText = "会社案内" };
                sysCategoryList.Add(category1);
                category1.SubCategories.Add(new Category() { MenuPriority = 1, MenuText = "クローバーの理念", ParentCategory = category1 });
                category1.SubCategories.Add(new Category() { MenuPriority = 1, MenuText = "優しい点", ParentCategory = category1 });

                Category category2 = new Category() { IsSystem = true, MenuPriority = 0, MenuText = "レッスンのご案内" };
                sysCategoryList.Add(category2);

                sysCategoryList.Add(new Category() { IsSystem = true, MenuPriority = 0, MenuText = "教材" });
                sysCategoryList.Add(new Category() { IsSystem = true, MenuPriority = 0, MenuText = "学生様の声" });
                sysCategoryList.Add(new Category() { IsSystem = true, MenuPriority = 0, MenuText = "よくあるご質問" });
                sysCategoryList.Add(new Category() { IsSystem = true, MenuPriority = 0, MenuText = "連絡方法" });
                foreach (Category category in sysCategoryList)
                {
                    CategoryManager.Save(category);
                }
            }

            ViewData.Add("SysCategory1", sysCategoryList[1]);
            return View();
        }
 //public ActionResult PartialMenu(int parentCategoryId)
 //{
 //    return PartialView();
 //}
 private string GetMenuHtml(Category category)
 {
     StringBuilder sb = new StringBuilder();
     if (category == null || string.IsNullOrEmpty(category.MenuText))
         return sb.ToString();
     //string linkStr =
     //    string.Format(
     //        "@Html.ActionLink(item.MenuText, \"Article\", \"Home\", new {{ categoryId ={0} }}, null)",
     //        category.ID);
     string linkStr = string.Format("<a href=\"/Home/Article?categoryId={0}\">{1}</a>", category.ID, category.MenuText);
     sb.AppendFormat(@"<li>{0}", linkStr);
     if (category.SubCategories != null && category.SubCategories.Count > 0)
     {
         sb.Append("<ul>");
         foreach (Category subCategory in category.SubCategories)
         {
             sb.Append(GetMenuHtml(subCategory));
         }
         sb.Append("</ul>");
     }
     sb.AppendFormat(@"</li>");
     return sb.ToString();
 }