Copied to clipboard

Flag this post as spam?

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


  • Dipa 88 posts 370 karma points
    Jun 03, 2016 @ 06:56
    Dipa
    0

    filter by property is not working

    Hello,

    I want to filter the children of one tree node using its property.

    In document type I have in property called 'Category' which is multi node tree picker type property.

    @{
        string artId = "1251";
        var allSliders = Umbraco.TypedContentAtRoot().Where("DocumentTypeAlias == \"Slider\"").FirstOrDefault().Children;
    
        var categorySliders = allSliders.Where(c => c.GetPropertyValue("Category", true).Equals(artId);
    }
    

    But it is not filtering data with specified condition. Please guide me where I am wrong? where the mistake?

    Thanks, Dipa

  • Jordan 24 posts 182 karma points
    Jun 03, 2016 @ 08:33
    Jordan
    0

    Hello Dipa,

    Have you looked to see if allSliders is returning the correct list of nodes?

    the next thing I would look at is the Where clause, a multi node picker will return a list of node IDs in a coma separated list (1234,1235,1236). So is the where clause trying to see if any match and return that node to the list? or is it trying to return just that specific ID.

    If you want to return the node you can check if Category contains the ID, like so:

    var categorySliders = allSliders.Where(c => c.GetPropertyValue("Category", true).Contains(artId);
    

    If you want to just return the ID you will have to split the category picker and put it to a list then return the correct ID from the list.

    this link should help if you are trying to achieve the latter: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/multinode-treepicker

Please Sign in or register to post replies

Write your reply to:

Draft