开发者

ASP.NET MVC iterate through collection within collection

开发者 https://www.devze.com 2022-12-21 19:12 出处:网络
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

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

精彩评论

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