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 access propertis of some nested content but am having issues.
I can loop through the content and display 'Name' but can't access any of the properties of each item.
I have properties:
title, intro, image
and have tried:
@foreach (var page in CurrentPage.Site().Children.Where("Visible"))
var items = page.GetPropertyValue<IEnumerable<IPublishedContent>>("sectionPanels");
if (items != null)
@foreach (var child in items)
As i said it will get the value for @child.Name but I get the error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''Umbraco.Web.PublishedContentModels.ServiceProgramsSectionPanel' does not contain a definition for 'GetPropertyValue''
When trying to access @child.GetPropertyValue("title")
When debugging I see this for @child:
This is because the a nested content item is not a real content item and therefore has no name.
As you've got Models builder enabled, you can create a typed model of your nested content.
Make your foreach something like this:
foreach(var rawChild in items)
var child = new ServiceProgramsSectionPanel(rawChild);
I find doing this makes things easier.
As Dave mentions, Nested content isn't a full content item. It is what's called a disconnected content type (I think). That doesn't explain why the GetPropertyValue method isn't working, it works for me normally. But if you use a Typed Model, it works around it I find.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted