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
Hi, has something changed in v6 Razor for looping through nodes based on their nodetype alias?
This kind of loop always worked in my projects:
var yearfolders = Model.Content.Children.Where("NodeTypeAlias == \"MediaArticleYearFolder\"");
but in my recent Umbraco v6.1.5, I try to loop through the year folder under the 'media articles node' and the yearfolders variable is empty
thanks for your help,
Anthony
found it. Looking into the Umbrac v6 MVC Razor Cheatsheets, I see that the naming for NodeTypeAlias has changed to DocumentTypeAlias.
this is working now:
var yearfolders = Model.Content.Children.Where("DocumentTypeAlias == \"MediaArticleYearFolder\"");
your solution works fine.
but it would be nicer if you use it with lambda expression which will give you the full intelisense in visual studio
var yearFolders = Model.Content.Children.Where(x => x.DocumentTypeAlias == "MediaArticleYearFolder");
Hi Ali,
Thanks a lot for the tip!
I tried to use a lambda expression to check if a property of type true/false is false
var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue("pastResearch") == false);
but this doesn't work, I'm getting the message:
Error1Delegate 'System.Func<Umbraco.Core.Models.IPublishedContent,int,bool>' does not take 1 arguments
can you try this? you need to convert that to boolean first
var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue<bool>("pastResearch") == false);
oh I see, found out this also works:
var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue("pastResearch") != "1");
but your solution is better
thanks a lot!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
looping through nodes in v6 Razor
Hi, has something changed in v6 Razor for looping through nodes based on their nodetype alias?
This kind of loop always worked in my projects:
var yearfolders = Model.Content.Children.Where("NodeTypeAlias == \"MediaArticleYearFolder\"");
but in my recent Umbraco v6.1.5, I try to loop through the year folder under the 'media articles node' and the yearfolders variable is empty
thanks for your help,
Anthony
found it. Looking into the Umbrac v6 MVC Razor Cheatsheets, I see that the naming for NodeTypeAlias has changed to DocumentTypeAlias.
this is working now:
var yearfolders = Model.Content.Children.Where("DocumentTypeAlias == \"MediaArticleYearFolder\"");
your solution works fine.
but it would be nicer if you use it with lambda expression which will give you the full intelisense in visual studio
Hi Ali,
Thanks a lot for the tip!
Hi Ali,
I tried to use a lambda expression to check if a property of type true/false is false
var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue("pastResearch") == false);
but this doesn't work, I'm getting the message:
Error1Delegate 'System.Func<Umbraco.Core.Models.IPublishedContent,int,bool>' does not take 1 arguments
can you try this? you need to convert that to boolean first
oh I see, found out this also works:
var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue("pastResearch") != "1");
but your solution is better
thanks a lot!
is working on a reply...