The only way I've been able to do this with Umbraco 4.7.0 is so...
<umbraco:Macro runat="server" language="cshtml">
@{
int count = 0;
}
@foreach(var @item in Model.relatedLinks.link)
{
count++;
}
@count
</umbraco:Macro>
Ugly hack huh? I wouldn't suggest actually using this though... but it's the only way I could figure out how to get the count!
I believe there have been hugely significant improvements to DynamicNode/DynamicXml in the upcoming Umbraco 4.7.1 release - hopefully there's a more elegant solution for this problem.
Related links count
In Razor, how do you check the number (count) of related links? For example,
Thank you, in advance, for any help.
Hi Sean,
The only way I've been able to do this with Umbraco 4.7.0 is so...
Ugly hack huh? I wouldn't suggest actually using this though... but it's the only way I could figure out how to get the count!
I believe there have been hugely significant improvements to DynamicNode/DynamicXml in the upcoming Umbraco 4.7.1 release - hopefully there's a more elegant solution for this problem.
Cheers, Lee.
Yup, counting will be possible in 4.7.1. Just a few more weeks of patience, or use a nightly build. :)
I tested this in Umbraco 4.11.3.1 and it works:
@Model.RelatedLinks.Count() > 0
Because I read that, for performance reason it's better to use the GetProperty("alias") on @Model, I tried:
@Model.GetProperty("RelatedLinks").Count > 0
but this generates an error.
anyone knows why this fails?
Thanks for your help,
Anthony
is working on a reply...