Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Sep 12, 2013 @ 09:53
    Anthony Candaele
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 12, 2013 @ 10:07
    Anthony Candaele
    100

    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\"");

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 18, 2013 @ 11:54
    Ali Sheikh Taheri
    1

    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");
    
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 18, 2013 @ 14:44
    Anthony Candaele
    0

    Hi Ali,

    Thanks a lot for the tip!

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 18, 2013 @ 15:11
    Anthony Candaele
    0

    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

    do you know how I can check for a boolean value with a lambda expression?
    Thanks for your help,
    Anthony
  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 18, 2013 @ 15:29
    Ali Sheikh Taheri
    1

    can you try this? you need to convert that to boolean first

     var currentResearch = Model.Content.Children.Where(x => x.GetPropertyValue<bool>("pastResearch") == false);
    
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 18, 2013 @ 15:32
    Anthony Candaele
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft