layUI+mvc动态菜单控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using LayUIMvcTest.Models;
namespace LayUIMvcTest.Controllers
{
public class MainController : Controller
{
//
// GET: /main/

public ActionResult Index()
{
return View();
}

#region 加载菜单数据
/// <summary>
/// 加载菜单数据
/// </summary>
/// <returns></returns>
public string LoadMenu()
{
StringBuilder str = new StringBuilder();
wgh_schoolEntities db = new wgh_schoolEntities();
var menulist = db.sys_menu.SqlQuery("select top 100 * from sys_menu where sys_pid=0 and sys_state=0").ToList();
if (menulist != null)
{
foreach (var item in menulist)
{
var pid = item.id;
str.Append("<li>");
str.Append("<a href=\"javascript:;\">");
str.Append("<i class=\"iconfont\">&#xe6b8;</i> <cite>" + item.sys_menuname + "</cite> <i class=\"iconfont nav_right\">&#xe697;</i>");
str.Append("</a>");
var childmenulist = db.sys_menu.SqlQuery("select top 100 * from sys_menu where sys_pid=" + pid + " and sys_state=0").ToList();
if (childmenulist != null)
{
str.Append("<ul class=\"sub-menu\">");
foreach (var submenu in childmenulist)
{
str.Append("<li>");
str.Append("<a _href=\"/" + (submenu.sys_menuurl) + "\">");
str.Append("<i class=\"iconfont\">&#xe6a7;</i> <cite>" + submenu.sys_menuname + "</cite>");
str.Append("</a>");
str.Append("</li>");
}
str.Append("</ul>");
}
str.Append("</li>");


}
}
return str.ToString();

}
#endregion
}
}

posted @ 2020-06-01 21:59  .net&new  阅读(572)  评论(0编辑  收藏  举报