views:

67

answers:

3

I have list of book titles and I have to list chapters like this.

Title 1 
       Chapter1
       Chapter2
       Chapter3
       Chapter4
Title 2 
       Chapter1
       Chapter2

So, I have list inside a list. I can get list of books (and titles) but when i reference their chapters i get nothing. well, how can I do that?

<% foreach (var item in Model) { %>

    <table>
        <tr>
            <th></th>
            <th>
                <%= Html.Encode(item.Text) %>
            </th>
        </tr>

        <% foreach (var chapters in item.Chapter){%>
        <tr>
            <td>
                <%=Html.Encode(chapters.Number)%>
            </td>
            <td>
                <%=Html.Encode(chapters.Text)%>
            </td>
        </tr>
        <% } %>
    </table>    

    <% } %>
A: 

It sounds like you don't have any chapters contained in your item.Chapter property. Can you check that they do exist- ie you are adding them somewhere in your logic. A breakpoint in the view would be one way of confirming this.

RichardOD
+1  A: 

Did you remember the Include attribute in your linq2entities query

See loading-relations-in-linq2entities-automatically

slamidtfyn
is this proper way to do it?
Ante B.
It's the only way to do it, afaik
slamidtfyn
That is one way. The other way would be projection.
Craig Stuntz
A: 

Logic written in the code is correct. Check whether the entries are there in the sub-list

Madhu