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
Using the Nested Content.
I wanted to return a list of my nested document types objects, but dont know how.
So, at firts, I tried to just use my Nested property, but it return a IEnumerable<IPublishedContent> instead list of my strongly typed nested objects. It does't let me use direct syntax like item.MyProperty.
// does'not works
var items = Model.Content.MyNestedItems;
foreach (var item in items)
@item.MyProperty // Not found coz it a IPublishedContent
How to do it propely?
Can you try the following:
OR you could try:
Let me know how it goes.
Thanks, Craig. It helped, but it still doesn't let use a direct syntax.
Do an other options exist?
May be a library or other approach?
var ncItems = Model.Content.MyNestedItems;
foreach (var ncItem in ncItems)
// Article - is MY model
// You might want to do a switch/if statement to assign the nc Item to the right Model
// A way to determine the type of ncItem is by it's DTA
// string nodeAlias = ncItem.DocumentTypeAlias;
var item = new Article(ncItem);
Thank you, Paul. It is exactly what i wanted!
Now, I have an idea to create a generic class to use it as a model instead UmbracoTemplatePage (and inherit that class).
I usually do like
Model.Content.NestedItems.Select(x => new Article(x))
I think you could also do
foreach (Article article in Model.Content.NestedArticles)
But as Paul wrote, a switch for determining the model if there is more than one type in the nest, would be necessary.
Tnak you, Søren
I will use it too.
Write your reply to:
Image will be uploaded when post is submitted