关于大类小类的输出问题

当要输出 类别 ----类别下的小分类

     类别-----类别下的小分类

Model

    /// <summary>
    /// 词条的列表  有百科类型
    /// </summary>
    public class WordList
    {
        public string BaikeType { get; set; }
        public Guid BaikeTypeID { get; set; }
        public List<Word> List { get; set; }
    }

 

Linq查询语句:

 

var list = from t in _db.BaiKeType
                           select new WordList
                           {
                               BaikeType = t.Name,
                               BaikeTypeID = t.ID,
                               List = (from w in _db.Word
                                       where w.BaikeTypeID == t.ID
                                       select w).ToList<Word>()//有点子查询的意思
                           };
                return list.ToList<WordList>();

//前台输出

 

<%List<SouGeWeb.Models.WordList> list = ViewData["list"] as List<SouGeWeb.Models.WordList>;%>
        <%foreach (SouGeWeb.Models.WordList item in list)
          {%>
        <h3>
            <%=item.BaikeType %></h3>
        <ul>
            <%foreach (SouGeDB.Word word in item.List)
              {%>
            <li><a href="/gebing.html?bId=<%=word.ID %>">
                <%=word.Title%></a></li>
            <%} %>
        </ul>
        <% } %>

posted @ 2012-09-26 17:39  南潇湘  阅读(126)  评论(0编辑  收藏  举报