Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bruce Canino 21 posts 42 karma points
    Apr 16, 2011 @ 03:37
    Bruce Canino
    0

    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?

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 16, 2011 @ 15:17
    Sebastiaan Janssen
    0

    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.

  • Bruce Canino 21 posts 42 karma points
    Apr 18, 2011 @ 19:33
    Bruce Canino
    0

    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 ?

Please Sign in or register to post replies

Write your reply to:

Draft