Umbraco - Get preliminary data from several data types of a drop-down list and create an unordered list using Razor

I just can't find how to create an unordered list for Umbraco.

I can get the prevalence, BUT I can not get them as a list on the front side.

My code so far:

var myValues = umbraco.library.GetPreValues(12080); <ul> @foreach(var c in myValues){ <li><a href="@ baseNode.Url?category=@c ">@c</a></li> } </ul> 

I return values ​​as a single element

but they are not divided. I tried adding .Split () to myValues ​​in foreach and threw me an error. Did I miss something?

Thanks in advance.

+3
source share
1 answer

This is because umbraco.library.GetPrevalues(int id) returns an XPathNodeIterator , so simply repeating the values ​​will not suffice. In the Umbraco Wiki, you can find a great example on how to XPathNodeIterator and select predicates using XPathNodeIterator . I rewrote it according to the Razor context:

 @using System.Xml.XPath @using umbraco.MacroEngines @inherits DynamicNodeContext @try { var baseNode = Model.AncestorOrSelf(); XPathNodeIterator iterator = umbraco.library.GetPreValues(1094); iterator.MoveNext(); //move to first XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", ""); @preValues.Count <ul> @while (preValues.MoveNext()) { string preValue = preValues.Current.Value; <li><a href="@ baseNode.Url?category=@preValue ">@preValue</a></li> } </ul> } catch (Exception e) { @e.ToString() } 
+6
source

All Articles