views:

36

answers:

2

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 collection)

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>
+1  A: 

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>
Darin Dimitrov
it doesnn't works
Massimo
That's very descriptive.
Darin Dimitrov
A: 

Missing closing > on inner li?

Andy Robinson
edited the first post
Massimo