开发者

Cycle categories with subcategories

1) i have 2 tabs Categories and SubCategories on db with relation 1 to many (im using entity framework)

2) i have to create a vertical menu like this

<ul>
   <li>category 1
    <ul>
       <li>subcategory 1</li>
       <li>subcategory 2</li>      
       <li>subcategory 3</li>
    </ul>
   </li>
</ul>

i think that my problem is here in my function

 Function List_category_subcategory() As List(Of WHAT HERE???????)

        Using db As New DBTestEntities

            Dim q = From cat In db.categories Join subcat In db.subcategories On cat.CategoryID Equals subcat.CategoryID _
            Select New With {cat.CategoryName, subcat.SubCategoryName}

        List_category_subcategory = WHAT HERE???????

        End Using

    End Function

because i dont know what function have to return (maybe a list col开发者_运维技巧lection)

After it on my view have to cycle everything

something like that

<ul> 
<%  For Each cat In ??????%>
 <li><a href="#"><%=Html.Encode(cat.CategoryName)%></a>
            <ul>
            <% For Each subcat In ???????%>          
            <li><%=Html.Encode(subcat.SubCategoryName)%></li>
            <% Next%>
            </ul>
</li>
<% Next%>
</ul>


Shouldn't SubCategory be a property of category (it kind of seems more natural but I could be wrong here)? Also you have a malformed li tag in the nested loop (<li<%=):

<ul id="menu-1" class="menu"> 
    <% For Each category In Model.Category %>
    <li>
        <a href="#"><%= Html.Encode(category.CategoryName) %></a>
        <ul>
        <% For Each subcategory In category.SubCategory %>          
            <li>
                <%= Html.Encode(subcategory.SubCategoryName) %>
            </li>
        <% Next %>
        </ul>
    </li>
    <% Next %>
</ul>


Missing closing > on inner li?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜