@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?)
Hi. It seems to me that the problem lies in the expression 'node.Children.OrderBy("CreatedDate").Take(2)'. Since 'node' is declared as a dynamic, the 'Children' property and following methods are all called dynamicaly. I would recomend to try and check (e.g. inside a dubugger) what a runtime type exactly is returned by the 'Children' property. (Or probably someone here know it for sure and can help, because personally I'm not that strong in using Razor along with Umbraco API).
Cannot Implicity Convert Error using Razor Macro
@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?)
Hi. It seems to me that the problem lies in the expression 'node.Children.OrderBy("CreatedDate").Take(2)'. Since 'node' is declared as a dynamic, the 'Children' property and following methods are all called dynamicaly. I would recomend to try and check (e.g. inside a dubugger) what a runtime type exactly is returned by the 'Children' property. (Or probably someone here know it for sure and can help, because personally I'm not that strong in using Razor along with Umbraco API).
I managed to solve it, below is the code:
@inherits umbraco.MacroEngines.DynamicNodeContext
@foreach (var item in @Model.NodeById(1121).Children.OrderBy("EventDateTime").Take(2))
{
<div class="column-holder">
<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>
}
is working on a reply...