开发者

ASP.NET MVC iterate through collection within collection

I have an ASP.NET MVC app in which I am iteratin开发者_如何学运维g through a Linq result set. Each row in the result set contains a property which is an EntitySet itself. When I try to iterate through the inner result set, I get an error message: "Invalid object name EntitySetOfSubItem" when trying to load the page. How do I process this collection?

<% foreach item in Model { %>
    ... code
    <% foreach subitem in item.EntitySetOfSubItems { %>


You would do it something like this:

<% foreach(YourType item in Model) { %>
    ... code
    <% foreach(OtherType subitem in item.EntitySetOfSubItems) { %>

By typing the iteration variable, you inform the compiler what attributes are available on the subitem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜