首页 > Web开发 > 详细

layUI+mvc动态菜单控制器

时间:2020-06-01 23:21:11      阅读:57      评论:0      收藏:0      [点我收藏+]

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
}
}

layUI+mvc动态菜单控制器

原文:https://www.cnblogs.com/wugh8726254/p/13027751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!