Copied to clipboard

Flag this post as spam?

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


  • Gayathri 55 posts 175 karma points
    Jun 13, 2017 @ 02:06
    Gayathri
    0

    Get Propert Value not listing the for each

    i am using CurrentPage.GetPropertyValue("promo") but the for each not loop thorugh

     @{
    
      var SiteLinks = CurrentPage.GetPropertyValue("promo");
        if (CurrentPage.HasValue("promo"))
        {
            var promoListValue = CurrentPage.GetPropertyValue("promo");
    
         foreach (var item in promoListValue)
                {
                    <span>@item.alias </span>
                }
    
    
        }
    }
    

    i am receive an error but when i print the promoListValue its displaying like this

    [ { "alias": "1", "content": "1", "img": "/media/1069/509253678.jpg" }, { "alias": "Slide 2", "content": "2", "img": "/media/1074/636609180.jpg" } ]
    

    can someone help me on this :)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 13, 2017 @ 10:41
    Alex Skrypnyk
    0

    Hi Gayathri

    What type of "promo" property? CurrentPage.GetPropertyValue("promo") returns object, you can't loop through object.

    Thanks,

    Alex

  • Alex Brown 129 posts 620 karma points
    Jun 13, 2017 @ 14:02
    Alex Brown
    0

    In Umbraco 7.5 you can do

    foreach (var item in CurrentPage.Promo)
    {
      @item.Alias
    }
    

    CurrentPage.Promo should return a dynamic type, which can be looped through. Just be careful because it'll be easy to run into errors.

    Not tried this method in 7.6

  • Gayathri 55 posts 175 karma points
    Jun 14, 2017 @ 01:04
    Gayathri
    0

    foreach (var item in CurrentPage.Promo) { @item.Alias }

    This solution throws an error

    : Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'char' does not contain a definition for 'Alias'

  • Gayathri 55 posts 175 karma points
    Jun 14, 2017 @ 01:03
    Gayathri
    0

    yeah, i know but i am looking for the solutions :)

    do u have any suggestion how can i convert

  • Alex Brown 129 posts 620 karma points
    Jun 14, 2017 @ 06:28
    Alex Brown
    0

    What do you need to convert it into?

  • Gayathri 55 posts 175 karma points
    Jun 15, 2017 @ 05:53
    Gayathri
    0

    my array is not loop thorugh its printing a strings enter image description here

  • Alex Brown 129 posts 620 karma points
    Jun 15, 2017 @ 06:10
    Alex Brown
    0

    Weird, it thinks that the promo value is a string and for each iteration it's using the next char.

    Anyway, have you tried using Json.Decode() ? This will convert an object which is JSON into a dynamic which can be looped

Please Sign in or register to post replies

Write your reply to:

Draft