Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    May 08, 2012 @ 09:29
    Anthony Candaele
    0

    OrderBy not working in my Razor script

    Hi,

    Does anyone know why this OrderBy statement in my Razor script produces an error?:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
        var year DateTime.Now.Year;
        DynamicNode yearfolder @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" year "\"").First();
        DynamicNodeList publications yearfolder.GetChildrenAsList;
    }


    <div class="C00_Clean container">
      <div class="widget-title">Latest publications</div>
      <div id="twitter" class="widget widget-twitter">
      @foreach (DynamicNode publication in publications.OrderBy("createDate desc"))
      {
          publication.Name;
      }
    </div>
      </div>

    The intellisense message in VS when I hover over the OrderBy statement is: "The type arguments can not be inferred from the usage. Try specifying the type arguments explicitly"

    How can I solve this?

    Thanks for your help,
    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    May 08, 2012 @ 09:43
    Anthony Candaele
    0

    I should more trust VS intellisense :) this works:

    @foreach (DynamicNode publication in publications.OrderBy<DynamicNode>("createDate desc"))

      {

          @publication.Name;

      }

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 11:27
    gilad
    1

    Hi Anthony.

    try this : 

    dynamic publications = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children;

    DynamicNodeList sortPublications = publications.OrderBy("createDate desc");

    @foreach (DynamicNode publication in  sortPublications )
      {
          publication.Name;
      }

    Or : 

    DynamicNodeList publications =  @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children.OrderBy("createDate desc");

    @foreach (DynamicNode publication in   publications  )
      {
          publication.Name;
      }

    Hope that help. Cheers

  • gilad 185 posts 425 karma points
    May 08, 2012 @ 11:29
    gilad
    1


    Just now saw your second message.

    :)

  • Anthony Candaele 1197 posts 2049 karma points
    May 08, 2012 @ 11:35
    Anthony Candaele
    0

    Hi gilad, no problem, I'm glad I could solve a Razor problem myself for once. Maybe your code will help someone else struggling with Razor.

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft