Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have the following data in umbraco.conf
<glossary> <items> <item> <data alias="term">Term1</data> <data alias="defind">Def1</data> </item> <item> <data alias="term">Term2</data> <data alias="defind">Def2</data> </item> <item> <data alias="term">Term3</data> <data alias="defind">Def3</data> </item> </items> </glossary>and I have the following razor macro that currently works.
<umbraco:Macro runat="server" language="cshtml">@foreach(var item in Model.glossary ) { <h3>@item.data[0].InnerText</h3> <p>@item.data[1].InnerText</p> }</umbraco:Macro>
I want to sort on the text of the data[0] and I tried a bunch of things, but I guess I not undersanding the OrderBy Clause
<umbraco:Macro runat="server" language="cshtml">@foreach(var item in Model.glossary.OrderBy("item.data[0].InnerText") ) { <h3>@item.data[0].InnerText</h3> <p>@item.data[1].InnerText</p> }</umbraco:Macro>
Any help here?
Looks like the DynamicXml type does not have an OrderBy method. You should probably create a generic list of items and sort that one,then do the rendering.
Thank you for your reply, but I guess I am still a nub on this. Is there a generic list type? How do a assign it?
something like
var list = Model.glossary ?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor OrderBy Help
I have the following data in umbraco.conf
<glossary>
<items>
<item>
<data alias="term">Term1</data>
<data alias="defind">Def1</data>
</item>
<item>
<data alias="term">Term2</data>
<data alias="defind">Def2</data>
</item>
<item>
<data alias="term">Term3</data>
<data alias="defind">Def3</data>
</item>
</items>
</glossary>
and I have the following razor macro that currently works.
<umbraco:Macro runat="server" language="cshtml">
@foreach(var item in Model.glossary )
{
<h3>@item.data[0].InnerText</h3>
<p>@item.data[1].InnerText</p>
}
</umbraco:Macro>
I want to sort on the text of the data[0] and I tried a bunch of things, but I guess I not undersanding the OrderBy Clause
<umbraco:Macro runat="server" language="cshtml">
@foreach(var item in Model.glossary.OrderBy("item.data[0].InnerText") )
{
<h3>@item.data[0].InnerText</h3>
<p>@item.data[1].InnerText</p>
}
</umbraco:Macro>
Any help here?
Looks like the DynamicXml type does not have an OrderBy method. You should probably create a generic list of items and sort that one,then do the rendering.
Thank you for your reply, but I guess I am still a nub on this. Is there a generic list type? How do a assign it?
something like
var list = Model.glossary ?
is working on a reply...