1
votes
@inherits umbraco.MacroEngines.DynamicNodeContext
@using System
@using System.Linq
@using System.Xml.Linq
@{
dynamic node = new umbraco.MacroEngines.DynamicNode(1121);

 }


 @foreach (dynamic group in node.Children.OrderBy("CreatedDate").Take(2))
 {
<div class="column-holder">
@foreach (var item in group )
{
      <div class="cell">

         <h3>@item.Name</h3>
        <em>@String.Format("{0:dddd, MMMM d yyyy}", item.EventDateTime) - Starts at @String.Format("{0:HH:mm}", item.EventDateTime)</em><br />
        <span>@(Library.Truncate(Library.StripHtml(item.EventDescription), 50, true))</span>
         <p class="readmore-link"><a href="@item.Url" class="link more">read more</a></p>      

       </div>


}
</div>

}

The following error I get when i try to run the above micro on homepage:

Error loading Razor Script ~/macroscripts/eventhomepage.cshtml Cannot implicitly convert type 'umbraco.MacroEngines.DynamicNode' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)

1

1 Answers

0
votes

I use this structure quite a bit to do similar things

IEnumerable<DynamicNode> nodeList = new DynamicNode(1121).Descendants(2).Items.OrderBy(x => x.CreateDate).Take(2);
List<DynamicNode> nodes = nodeList.ToList(); 

and then your foreach would just be

foreach(DynamicNode group in nodes)

and make sure you add

@using umbraco.MacroEngines