MVC多级目录菜单  ----- 简单模拟

Model ---- cs

{
public class Class1
{
public int ID{get;set;}
public int parentID { get; set; }
public int childID { get; set; }
public string title { get; set; }
}

MVC View ---- cshtml:

@using WebApplication1.Models;
@{
ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3> <p>Use this area to provide additional information.</p> @{
var totalList = new List<Class1>();//全部目录列表
totalList.Add(new Class1{ ID = ,parentID = , title = "title_1"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_5"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_12"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_2"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_3"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_4"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_6"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_7"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_8"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_9"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_10"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_11"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_13"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_14"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_15"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_16"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_17"});
totalList.Add(new Class1{ ID = ,parentID = , title = "title_18"});
foreach (var item in totalList){
<ul>
@if (item.parentID == )
{//如果为一级目录
<li>@item.title</li>
if (totalList.Find(x => x.parentID == item.ID ) != null)
{
@Show(item);
}
}
</ul>
}
} @helper Show(Class1 item){
var totalList = new List<Class1>();//全部目录列表
totalList.Add(new Class1 { ID = , parentID = , title = "title_1" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_5" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_12" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_2" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_3" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_4" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_6" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_7" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_8" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_9" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_10" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_11" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_13" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_14" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_15" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_16" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_17" });
totalList.Add(new Class1 { ID = , parentID = , title = "title_18" });
<ul>
@for (int i = ; i < totalList.Count; i++){
if (item.ID == totalList[i].parentID){
<li>@totalList[i].title</li>
if (totalList.Find(x => x.parentID == totalList[i].ID) != null){
@Show(totalList[i]);
}
}
}
</ul>
}

MVC 多级目录菜单的更多相关文章

  1. 二、处理MVC多级目录问题——以ABP为基础架构的一个中等规模的OA开发日志

    就个人感觉而言.ASP.NET MVC是一种非常反人类的设计.(我没有接触过Java的MVC,不知道两者是否一样.如果一样,那么搞Java的同学也挺可怜.)尤其是MVC的路由机制,灰常灰常反动.路由所 ...

  2. asp.net mvc多级目录结构和多级area实现技巧

    今天在工作要实现这个多级area.其原因是这个项目需要多级的功能,大的类别里有小的类别,小的类别里有具体的功能项,每一个功能项还有若干动作Action,所以在菜单和mvc工程的结构上都需要有体现多级的 ...

  3. MVC 多级目录(控制器) 路由重写 及 多级Views目录 的寻找视图的规则

    转自:[原]Asp.net Mvc   多级控制器 路由重写 及 多级Views目录 的寻找视图的规则 asp.net mvc 为了更好的控制views的页面存放,和控制器的可读性,需要分开多级目录来 ...

  4. 洗礼灵魂,修炼python(78)--全栈项目实战篇(6)—— 多级目录菜单之地址管理系统

    相信各位都在在网上买过东西吧?那么今天我的主题就是写个在线购物系统,是不可能的,哈哈(后期确实有这个项目),那么购物都填写过快递地址吧?然后网上查个地址都有地址管理吧? 要求: 1.打印出省.市.县等 ...

  5. asp.net mvc 多级目录结构

    ikmb@163.com ASP.NET MVC默认的文件组织和URL访问都是一级,我们通常要将一个功能模块组织到一个目录下.方法是:1.文件组织 分别在Controllers和Views文件夹下建议 ...

  6. 洗礼灵魂,修炼python(79)--全栈项目实战篇(7)—— 多级目录菜单之地址管理系统升级版

    要求: 1.在上一篇的地址管理系统的基础上做升级改动 2.添加增删改的功能 3.尽量的贴近生活常识中的地址管理 分析: 需求不用多说了,干就完了 相关文件源码地址:github 这次由于要有增删改的操 ...

  7. Asp.net Mvc 多级控制器 路由重写 及 多级Views目录 的寻找视图的规则 (多级路由) 如:Admin/Test/Index

    http://blog.csdn.net/buhuan123/article/details/26387427 目录(?)[-] 1那么我们再来看我们需要的访问方式如下图 razor视图的地址写成通配 ...

  8. jQuery插件——多级联动菜单

    jQuery插件——多级联动菜单 引言 开发中,有好多地方用到联动菜单,以前每次遇到联动菜单的时候都去重新写,代码重用率很低,前几天又遇到联动菜单的问题,总结了下,发现可以开发一个联动菜单的功能,以后 ...

  9. 基于jQuery垂直多级导航菜单代码

    基于jQuery垂直多级导航菜单代码是一款黑色风格的jQuery竖直导航菜单特效下载.效果图如下: 在线预览   源码下载 实现的代码. html代码: <ul class="ce&q ...

随机推荐

  1. python(三)set集合

    set集合的特点是无序.不重复序列 创建集合: 1 2 3 4 5 6 7 8 9 10 11 12 13 a.s1 = {11,22} b.s2 = set() c.s3 = set([11,22, ...

  2. sql2008 表名为全数字时查询报错

    今天遇到个很奇葩的问题,在写一个应用程序时需要查询表的数据,但是表名是全数字的,直接查询会报错,于是想到给111的表名加一对中括号:即——>select * from [111] 刚开始还是报错 ...

  3. 关于无法把程序(Adobe Fireworks CS5)添加到打开方式的解决办法

    关于无法把程序(Adobe Fireworks CS5)添加到打开方式的解决办法 最近换了新版的Adobe Fireworks CS5,发现打开图片文件时在右键“打开方式”里仍然是以前的Firewor ...

  4. <转>修改TM2013聊天记录保存目录final版

    一直很钟意TM的清爽,然而在升级到TM2013 preview1后,发生了一件很让人头痛的事.    那就是无法设定消息目录,TM会默认为保存在我的文档下.这让使用dropbox同步聊天记录的我感到十 ...

  5. 一键式Spring集成工具 Spring Boot

    最近公司使用Spring boot进行开发,稍微了解一下,不过自我感觉把集中式配置applicate.properties搞明白,注解用过Spring MVC的boot绝对没问题的 比如拦截器:@As ...

  6. jQuery的环境配置

    目前最新的版本,是 1.10.1 和 2.0.2,如果你需要引用到你线上的项目,就必须使用压缩版,去掉了注释和空白,是容量最小. 从CDN中载入JQuery,如Google中载入JQuery: htt ...

  7. python无意中发现的

    http://www.zhihu.com/question/37904398?sort=created&page=2 >>> a = [[1,2],[3,4],[5,6,7] ...

  8. 樱花漫地集于我心,蝶舞纷飞祈愿相随---总结 浮动:flux 浮动:flux

    知识点 数据类型,运算符与表达式: 程序结构:顺序,选择,循环 问题 各种结构,单词意思 心得体会 抄程序是最笨的方法但我认为它是进步最快的方法,抄程序是积累经验的时候,而做项目才是真正把所学为所用的 ...

  9. MFC List Control 控件添加单元格编辑,实现可编辑重写

    在实现随机生成四则运算的个人项目中,目前已经完成基本功能,想要把程序变成一个Windows界面的程序.原本以为学习过MFC,应该很快就能完成.但是由于以前用的都是VC6.0,这次用了VS2010,稍微 ...

  10. PHP数组去重..............过滤字段

    $test_data = M('hot'); //实例化数据表 $data = $test_data->Distinct(true)->field('descriprion')->o ...