It's generally best to use the Property Value converters, it makes things alot easier.
You should be able to simply do this:
@if (Model.Content.HasValue("tags"))
{
if (Model.Content.Tags != null)
{
foreach (var tag in Model.Content.Tags)
{
<div class="badge badge-info">@tag</div>
}
}
}
This is because the conversion from a comma separated list is happening in the Property Conversion so you don't need to do anything with it. The property just gives you back the array of strings to iterate around :-)
Getting tags field only gives me a System.string[] string
I'm trying to render a list of article tags but all I get is a single string of
System.string[]
.I know the article has tags added to it. So what am I doing wrong?
Hi Johan,
you mean something like this:
Hope this helps!
/Michaël
Hey Michaël!
I tried your version too with the same result.
I get
<div class="badge badge-info">System.string[]</div>
rendered out. =/Johan,
which version are you using?
There has been a change in the property value convertors, can you try to disable them and try again:
In
umbracoSettings.config
setEnablePropertyValueConverters
to false.Hope this helps!
/Michaël
It's 7.8.1.
Setting that to false breaks the rendering of the pages.
It's 7.8.1.
Setting that to false breaks the rendering of all pages.
Hi Johan,
It's generally best to use the Property Value converters, it makes things alot easier.
You should be able to simply do this:
This is because the conversion from a comma separated list is happening in the Property Conversion so you don't need to do anything with it. The property just gives you back the array of strings to iterate around :-)
Thanks,
Nik
That did it! Thanks Nik!
No problem, happy to help :-)
Aha something new learned today! Thanks!
/Michaël
I'm trying to do something similar but with no luck. This is my code:
But all I get is System.string[]
What am I doing wrong here?
Hi Joop,
The issue you have is most likely this:
You are explicitly telling the property converters to turn tags into a single string, when you actually want it to be an enumerable object.
Try replacing it with this line:
and see how you get on.
Thanks,
Nik
Hi Nik,
You're a life saver. Did this the trick!
Thanks a bunch!!
Joop
Hello,
I am on Umbraco 8 and when rendering the list chosen from my checkboxlist is giving me : System.String[]
Can someone please help.
Thanks.
are you just calling .ToString() on your value?
a
System.String[]
is an array, and you need to iterate it to render each valueis working on a reply...