Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Dec 05, 2015 @ 16:46
    Niklas Hjelm
    0

    Problem with foreach and numeric property

    Hi, I have a numeric property called grade set to my pages. I'm trying to get the pages based on grades and tried with

    @{
      dynamic node = new umbraco.MacroEngines.DynamicNode(1059);
    }
    
    @foreach (var page in node.Children.Where("grade < 3").OrderBy("CreateDate desc"))
    {
      @page.name
    }
    

    This is not working. I've also tried getting the levels with a simple if statement but then it cannot find the property "grade". Any ideas on how to solve this? Thanks

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 08, 2015 @ 17:55
    Alex Skrypnyk
    0

    Hi Niklas,

    Did you try IPublishedContent type instead of dynamic?

    @{
      var node = new Umbraco.TypedContent(1059);
    }
    
    @foreach (var page in node.Children.Where(x => x.GetPropertyValue<int>("grade") < 3).OrderBy(x => x.CreatedDate)
    {
      @page.Name
    }
    

    Thanks, Alex

  • Niklas Hjelm 104 posts 125 karma points
    Feb 27, 2016 @ 07:50
    Niklas Hjelm
    0

    Hi Alex, thanks for replying. When I try your solution I can that "TypedContent" is missing an assembly reference. Do you know how to fix that?

    Thanks / Niklas

Please Sign in or register to post replies

Write your reply to:

Draft