Copied to clipboard

Flag this post as spam?

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


  • Marky 26 posts 65 karma points
    Feb 08, 2019 @ 08:25
    Marky
    0

    How to get the multiple IDs in Examine

    Hi guys,

    How can I get this three (3) ideas, and get their properties.

    /// Umbraco/Api/Search/ComparisonKeyValues?ids=2874,2875,2876
    public List<Compares> ComparisonKeyValues(string ids)
    {
        // what should I put here...
    }
    

    Appreciate any help,

    Thanks in advance,

    Marky

  • Craig Mayers 164 posts 508 karma points
    Feb 11, 2019 @ 16:17
    Craig Mayers
    0

    Hi Marky,

    Are those ID's for ContentNodes OR MediaNodes?

    If they are for Content then you can use the following to get back the Node properties for:

    var selectedNode = Umbraco.TypedContent(2874);
    

    Then you could pull properties off from this object in code like below:

    var nodeUrl = selectedNode.Url;
    var nodeName = selectedNode.Name;
    

    If they are for Media then use the following:

        var selectedMediaNode = Umbraco.TypedMedia(2874);
    

    Then access properties of the Media node like so:

    selectedMediaNode.Url;
    

    etc.

    The following document will be really helpful for you: UmbracoHelper

    Thanks

    Craig

  • Marky 26 posts 65 karma points
    Feb 14, 2019 @ 09:59
    Marky
    0

    Hi Craig,

    Thanks for your help, I actually got it :) https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/95629-how-to-get-3-values-using-keyvaluepair

    public List<Compares> CompareValues(string ids)
    {
        var result = new List<Compares>();
    
        if (!string.IsNullOrEmpty(ids))
        {
            string[] listOdIds = ids.Split(new char[] { ',' });
    
            foreach (var id in listOdIds)
            {
                var page = Umbraco.TypedContent(id);
                var imageUrl = Umbraco.TypedMedia(page.GetPropertyValue<string>("image")).Url;
    
                var comparess = new Compares()
                {
                    Id = Convert.ToInt32(id),
                    Title = page.GetPropertyValue<string>("title"),
                    Url = imageUrl
                };
    
                result.Add(comparess);
            }
            return result;
        }
        return result;
    }
    

    Cheers,

    Marky

Please Sign in or register to post replies

Write your reply to:

Draft