Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 134 posts 287 karma points
    Dec 02, 2017 @ 04:55
    Jin Botol
    0

    How can I use lambda clause?

    Hi guys,

    I have a nuPicker with a dropdown list of builders, and its works fine. enter image description here

    However, I want to display all the Siblings with the same builder homes

    I've try

    @foreach (var builderId in CurrentPage.builder.PickedKeys)
    {
        <h4>@builderId</h4> //Get the selected builder ID
    
        foreach (var relatedItems in Model.Content.Siblings().Where(x => x.Id != Model.Content.Id && x => x.builderId == builderId).RandomOrder().Take(3))
        {
                 // do some stuff...
        }
    

    }

    How can I the lambda if they are the same in builderId?

    I'm using Umbraco v7.

    Thanks in advance,

    Jin

  • Ben Palmer 180 posts 866 karma points c-trib
    Dec 02, 2017 @ 09:17
    Ben Palmer
    0

    Hi Jin,

    Are you using Models Builder? If so I think your builderIdwill be BuilderId. If not they you need to use GetPropertyValue so your where clause would become:

    Model.Content.Siblings().Where(x => x.Id != Model.Content.Id && x.GetPropertyValue("builderId") != null && x.GetPropertyValue<string>("builderId") == builderId)
    

    Just to note as well, that you should only need to do x => once in your where clause, at the start.

  • Jin Botol 134 posts 287 karma points
    Dec 04, 2017 @ 02:39
    Jin Botol
    0

    Hi Ben,

    Thank you for response!

    But don't have display, the foreach statement is not TRUE.

    Or is there any other ways to implement related posts with the same in builderId?

    I have a limited knowledge in Umbraco.

    Regards,

    Jin

  • Jin Botol 134 posts 287 karma points
    Dec 05, 2017 @ 07:54
    Jin Botol
    0

    Hi guys,

    Still seeking for help :(

    Regards

    Jin

  • Ben Palmer 180 posts 866 karma points c-trib
    Dec 05, 2017 @ 08:35
    Ben Palmer
    0

    Hi Jin,

    Can you post your document types please (probably the one you're on now and the one with the picker)?

  • Jin Botol 134 posts 287 karma points
    Dec 05, 2017 @ 09:11
    Jin Botol
    0

    Hi Ben,

    Thanks for your fast response, I'm really new in Umbraco.

    Here's the structure of my project.

    enter image description here

    The nuPicker enter image description here

    nuPicker Data enter image description here

    Regards,

    Jin

  • Ben Palmer 180 posts 866 karma points c-trib
    Dec 05, 2017 @ 10:30
    Ben Palmer
    0

    Thanks Jin,

    Look like your property alias id should be builder, not builderId. Try the following:

    Model.Content.Siblings().Where(x => x.Id != Model.Content.Id && x.GetPropertyValue("builder") != null && x.GetPropertyValue<string>("builder") == builderId)
    
  • Jin Botol 134 posts 287 karma points
    Dec 06, 2017 @ 01:26
    Jin Botol
    0

    Hi Ben,

    No display again! Maybe the output of

    .GetPropertyValue<string>("builder")
    

    is JSON

    [ { "key": "3124", "label": "One Homes" } ]
    

    And theforeach statement is ...GetPropertyValue<string>("builder") == builderId and the builderId is an INT ?

    Regards,

    Jin

  • Jin Botol 134 posts 287 karma points
    Dec 06, 2017 @ 04:04
    Jin Botol
    0

    Hi Ben,

    What I've done now is;

    Successfully getting the nuPicker ID in each homes inside foreach loop.

    @ {
         // Get the selected nuPicker ID
         var BuilderId = CurrentPage.builder.PickedKeys[0];
    
         foreach (var relatedItems in Umbraco.Content(1099).Children)
            {
                // Get the nuPicker ID in each homes
                var relatedItemsid = relatedItems.GetPropertyValue("builder").PickedKeys[0];
            }
    }
    

    My Problem now is, I want to use the relatedItemsid in Where() or the lambda clause.

    Any help for this.

    Thanks in advance,

    Jin

Please Sign in or register to post replies

Write your reply to:

Draft