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 28 posts 168 karma points
    22 days ago
    Christian Hansen
    0

    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 5333 posts 19667 karma points MVP 3x admin c-trib
    22 days ago
    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 28 posts 168 karma points
    21 days ago
    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 5333 posts 19667 karma points MVP 3x admin c-trib
    21 days ago
    Alex Skrypnyk
    0

    What Umbraco version are you using?

  • Christian Hansen 28 posts 168 karma points
    21 days ago
    Christian Hansen
    0

    It is version 7.14.0

  • Alex Skrypnyk 5333 posts 19667 karma points MVP 3x admin c-trib
    20 days ago
    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 28 posts 168 karma points
    20 days ago
    Christian Hansen
    0

    Hi Alex,

    That worked! Thanks a lot for your help!

    Regards Christian.

Please Sign in or register to post replies

Write your reply to:

Draft