Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to get content by index from set, but it does't compile.
var set = Model.MyContent; // it is a NestedContent!
for (int i = 0; i < set.Count(); i++)
<p>@set[i].MyProperty</p> // Error!
Does better way exists?
All I want - render my content in rows
like that :
- item 1
- item 2
- item 3
- item 4
- item 5
- item 6
I tryed to use .Next() method, but it does,t works with NestedContent for some reason.
What version of Umbraco are you using?
"NestedContent" is it "IEnumerable
Try this code:
var set = Model.MyContent.ToList();
Thanks, Alex. It works!
Nested content is of type IEnumerable<IPublishedContent>. The IEnumerable interface doesn't support accessing items by index. In order to access by index you need to convert to either an Array or a List that does support addressing by index ie.
var items = Model.MyContent.ToList();
var items = Model.MyContent.ToArray();
However, it sounds like you want to break your content into equally sized groups? In that case, use the InGroupsOf() extension method. Something like:
var groups = Model.MyContent.InGroupsOf(3);
foreach (var group in groups)
@foreach (var item in group)
Dan, Thanks a lot! That is exactly what I wanted!
Yes, I realy wanted to group my content in equel groups and then render it!
I'm using Bootstrap 3 without flexboxes, so it hard to render grid when you have different height of content.
For other with same problem, I just leave solution here:
@foreach (var row in Model.MyContent.InGroupsOf(3))
@foreach (MyModel item in row)
<div class="col-xs-12 col-md-4 col-sm-4">
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted