DynamicNodeList does not contain a definition for 'Children'
Hi,
I'm trying to loop through all publications that are stored in a PublicationYearFolder. I'm filtering the publications on the publicationtype (article, book, bookchapter, conference proceeding) that was sent through a querystring.
my code looks like this:
@{
var publicationtype = HttpContext.Current.Request.QueryString["type"];
DynamicNodeList publications = new DynamicNodeList();
this code loops through all publicationyear folders, and if it finds a publiction of the publicationtype that was sent with the querystring, it adds the publication to a list of dynamic nodes, publist. At the end of each cycle through the publicationyearfolders there is a check to see if the publist has any items, if so, the publications are rendered.
This way all publications are filtered by publicationtype and sorted by year:
DynamicNodeList does not contain a definition for 'Children'
Hi,
I'm trying to loop through all publications that are stored in a PublicationYearFolder. I'm filtering the publications on the publicationtype (article, book, bookchapter, conference proceeding) that was sent through a querystring.
my code looks like this:
@{
var publicationtype = HttpContext.Current.Request.QueryString["type"];
DynamicNodeList publications = new DynamicNodeList();
if(publicationtype != null)
{
publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == publicationtype);
}
else
{
publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == "article");
}
}
<h1>@publicationtype</h1>
@foreach (DynamicNode publication in publications)
{
@publication.Name
}
The content tree looks like this:
However, when debugging the Razor script, I get this error:
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'
I don't understand this because when I write the line:
publications = @Model.PublicationFolderYear.Children.Where(Model.publicationType == "article");
I don't understand this, because in VS the Intellisense tells me that there is a 'Children' property
What am I doing wrong?
Thanks for your help,
Anthony
my bad, giving this code a second look made me realise it couldn't work.
This works though, all publicationyear folders are looped and every publication rendered:
@{
var publicationtype = HttpContext.Current.Request.QueryString["type"];
DynamicNodeList yearfolders = new DynamicNodeList();
yearfolders = @Model.Children;
}
<h1>@publicationtype</h1>
@foreach (DynamicNode folder in yearfolders)
{
<h3>@folder.Name</h3>
DynamicNodeList publications = folder.GetChildrenAsList;
{
foreach (DynamicNode publication in publications)
{
<p>@publication.Name;</p>
}
}
}
Now I just need to filter on 'publicationType'
Is `publicationType` just the Document Type Alias? If so, just do something like this:
Hi Grant,
No, publicationType is a property of the 'publication' documentype of custom datatype dropdown list
Thanks for your help,
Anthony
and now the filtering on publicationtype is also solved:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var publicationtype = HttpContext.Current.Request.QueryString["type"];
DynamicNodeList yearfolders = new DynamicNodeList();
yearfolders = @Model.Children;
}
<h1>@publicationtype</h1>
@foreach (DynamicNode folder in yearfolders)
{
<h3>@folder.Name</h3>
DynamicNodeList publications = folder.GetChildrenAsList;
{
foreach (DynamicNode publication in publications)
{
if (publication.GetProperty("publicationType").Value == publicationtype)
{
@publication.Name;
}
}
}
}
tweaked the code a little:
this code loops through all publicationyear folders, and if it finds a publiction of the publicationtype that was sent with the querystring, it adds the publication to a list of dynamic nodes, publist. At the end of each cycle through the publicationyearfolders there is a check to see if the publist has any items, if so, the publications are rendered.
This way all publications are filtered by publicationtype and sorted by year:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var publicationtype = HttpContext.Current.Request.QueryString["type"];
DynamicNodeList yearfolders = new DynamicNodeList();
yearfolders = @Model.Children;
List<DynamicNode> publist = new List<DynamicNode>();
}
<h1>@publicationtype</h1><br />
@foreach (DynamicNode folder in yearfolders)
{
DynamicNodeList publications = folder.GetChildrenAsList;
{
foreach (DynamicNode publication in publications)
{
if (publication.GetProperty("publicationType").Value == publicationtype)
{
publist.Add(publication);
}
}
}
if (publist.Count() != 0)
{
<h3>@folder.Name</h3>
foreach (DynamicNode publication in publist)
{
<p>@publication.GetProperty("publicationTitle").Value</p>
}
}
publist.Clear();
}
Hope this might be usefull to someone else, wandering just like me through Razorland :)
is working on a reply...