Copied to clipboard

Flag this post as spam?

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


  • Christian Hansen 34 posts 204 karma points
    Sep 02, 2019 @ 17:35
    Christian Hansen
    0

    Tags on member

    Hello, i am having som difficulty showing tags from the tags data type.

    I have a member with tags datatype with now 2 tags: "Talent" and "EYC"

    I get the member from the current page with following code:

    var iMember = ApplicationContext.Services.MemberService.GetById(Int32.Parse(Model.AthleteMemberPicker.ToString()));
    

    And then i am trying to show the tags attached to this member with following code:

    @{
                            if (iMember.GetValue("dBwFAthleteTags").ToString() != null)
                            {
                                                                string[] tagsList = iMember.GetValue("dBwFAthleteTags").ToString().Split(',');
                                    if (tagsList.Count() > 0)
                                    {
                                        @tagsList.Count()
                                        <ul>
                                            @foreach (var tag in tagsList)
                                            {
                                                <li>@tag</li>
                                            }
                                        </ul>
                                    }
    
                            }
                        }
    

    But on the screen it shows following:

    enter image description here

    It gives me each tag but it keeps the [" " " "] characters. How can i show them without these characters. And only show the tags value?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Sep 02, 2019 @ 20:13
    Alex Skrypnyk
    0

    hi Christian

    I think you have to use GetValue<>

    var tagsList = iMember.GetValue<IEnumerable<string>>("dBwFAthleteTags");
            if (tagsList.Any())
            {
                @tagsList.Count()
                <ul>
                    @foreach (var tag in tagsList)
                    {
                        <li>@tag</li>
                    }
                </ul>
            }
    

    Thanks, Alex

  • Christian Hansen 34 posts 204 karma points
    Sep 03, 2019 @ 09:46
    Christian Hansen
    0

    Hi Alex,

    Thanks for the reply!

    I have tried this, now it says "A value cannot be null" at the line "if (tagsList.Any())"

    enter image description here

    if i print out: "var tagsList = iMember.GetValue<>

    If i print out: "iMember.GetValue("dBwFAthleteTags").ToString()" it gives me: "["Talent","EYC"]"

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Sep 03, 2019 @ 10:20
    Alex Skrypnyk
    0

    What Umbraco version are you using?

  • Christian Hansen 34 posts 204 karma points
    Sep 03, 2019 @ 10:34
    Christian Hansen
    0

    It is version 7.14.0

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Sep 03, 2019 @ 22:53
    Alex Skrypnyk
    100

    Hi Christian

    What if we use UmbracoHelper:

    var memberTyped = Umbraco.TypedMember(Int32.Parse(Model.AthleteMemberPicker.ToString()));
    var tags = memberTyped.GetPropertyValue<IEnumerable<string>>("dBwFAthleteTags");
    

    Thanks,

    Alex

  • Christian Hansen 34 posts 204 karma points
    Sep 04, 2019 @ 06:27
    Christian Hansen
    0

    Hi Alex,

    That worked! Thanks a lot for your help!

    Regards Christian.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies