那是因为umbraco.library.GetPrevalues(int id)
返回一个XPathNodeIterator
如此简单地遍历值是不够的。在 Umbraco Wiki 中,您可以找到一个很好的示例,说明如何使用XPathNodeIterator
. 我重写了它以适应 Razor 上下文:
@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()
}