Copied to clipboard

Flag this post as spam?

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


  • Nso 18 posts 87 karma points
    Aug 16, 2017 @ 13:34
    Nso
    0

    Using tags property and wanted to render it. It is giving back "System.String[]".

    Please help me out.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Aug 29, 2017 @ 11:27
    Alex Skrypnyk
    0

    Hi Nso

    What wrong with tags rendering you showed?

    Thanks,

    Alex

  • Manish 373 posts 932 karma points
    Aug 29, 2017 @ 13:02
    Manish
    0
    @if (@Model.HasProperty("tags"))
    {
        string[] tagsList = Model.tags.ToString().Split(',');
    
        if (tagsList.Count() > 0)
        {
            <ul>
            @foreach (var tag in tagsList)
            {
                 <li>@tag</li>
            }
            </ul>
        }
    }
    
  • John Bergman 483 posts 1132 karma points
    Aug 29, 2017 @ 19:21
    John Bergman
    0

    If it is returning a string array, you would need something like this instead...

    @if (@Model.HasProperty("tags")) { string[] tagsList = Model.tags;

    if (tagsList.Count() > 0)
    {
        <ul>
        @foreach (var tag in tagsList)
        {
             <li>@tag</li>
        }
        </ul>
    }
    

    }

  • Jeremy Holland 20 posts 103 karma points
    Oct 24, 2017 @ 23:26
    Jeremy Holland
    0

    This is an issue for me in 7.7.3

    The object returned from a call to Umbraco.Field("seoKeywords") (which is a tags data type) is an IHtmlString, which contains the string "System.String[]" rather than an actual array of strings.

    What is the solution for this?

    EDIT: I was able to extract the tag datatype value using a strongly typed view and the following code: var tags = Model.Content.SeoKeywords.ToArray(); but I'm still confused as to why the Umbraco.Field method doesn't work

    MORE EDITS: Further testing using the CurrentPage object proves that I can get the tag datatype value using the following code: string[] tags = CurrentPage.seoKeywords;

  • William Charlton 171 posts 218 karma points
    Dec 29, 2017 @ 12:36
    William Charlton
    0

    I have exactly the same issue. I had a very handy XSLT script in a V6 site which now doesn't work. Snipertags was great but that now doesn't work. So I tried the Razor example as Jeremy has done and I get the same "System.String[]" Has someone broken V7.7.6 in the name of progress?

    Does anyone have an example of built in Tags actually working in a late version 7??

    It isn't fixed so break it?

  • Rajmond Burgaj 5 posts 86 karma points
    Dec 29, 2017 @ 15:04
    Rajmond Burgaj
    1

    You may use this syntax as below to get the tag array:

    var tagList = Model.Content.GetProperty("tags").Value as string[];
    
  • William Charlton 171 posts 218 karma points
    Jan 03, 2018 @ 11:01
    William Charlton
    2

    I have replaced the selector used, as shown on https://shermandigital.com/blog/display-umbraco-tags-on-razor-templates/ I replaced Sherman's

    var tagList = Umbraco.Field("articleTags").ToHtmlString().Split(',');
    

    with

    var tagList = Model.Content.GetProperty("tags").Value as string[];
    

    I replaced "tags" with my property name "pageTags" (Sherman uses "articleTags")

    var tagList = Model.Content.GetProperty("pageTags").Value as string[];
    

    And to display the tags? The code from Sherman Digital works. Thanks Rajmond!

  • Biagio Paruolo 1594 posts 1825 karma points c-trib
    Feb 17, 2018 @ 15:12
    Biagio Paruolo
    0
     string[] tags = CurrentPage.keywords;
     string keywordstags =   String.Join(",",tags);
    
Please Sign in or register to post replies

Write your reply to:

Draft