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
What it came down to is even with the right using statements etc you can’t hook into the extension methods.. is there something I’m missing?
First tried:
<umbraco:Macro runat="server" language="cshtml"> @using System.Linq @using umbraco.MacroEngines @inherits umbraco.MacroEngines.DynamicNodeContext @{ var collectionItems = @Model.Descendants("individualCollection"); var externalCollectionItems = Model.Descendants("externalCollection"); if(@collectionItems != null && @externalCollectionItems != null) { var allCollectionItems = collectionItems.Cast<DynamicNode>().Union(externalCollectionItems.Cast<DynamicNode>()); if(@allCollectionItems.Any()) { <ul> @foreach (var item in @allCollectionItems) { <li><a href="@item.Url">@item.Name</a></li> } </ul> } } } </umbraco:Macro>
And got:
Error loading Razor Script 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Cast
Then tried:
<umbraco:Macro runat="server" language="cshtml"> @using System.Linq @using umbraco.MacroEngines @inherits umbraco.MacroEngines.DynamicNodeContext @{ var collectionItems = @Model.Descendants("individualCollection"); var externalCollectionItems = Model.Descendants("externalCollection"); if(@collectionItems != null && @externalCollectionItems != null) { var allCollectionItems = collectionItems.ToArray().Cast<DynamicNode>().Union(externalCollectionItems.ToArray().Cast<DynamicNode>()); if(@allCollectionItems.Any()) { <ul> @foreach (var item in @allCollectionItems) { <li><a href="@item.Url">@item.Name</a></li> } </ul> } } } </umbraco:Macro>
Error loading Razor Script 'System.Array' does not contain a definition for 'Cast
Then we re-thought it... GOT THE LOGIC RIGHT as well as reduced it down and got:
<umbraco:Macro runat="server" language="cshtml"> @using System.Linq @using umbraco.MacroEngines @inherits umbraco.MacroEngines.DynamicNodeContext @{ var collectionItems = @Model.Descendants("individualCollection"); var externalCollectionItems = @Model.Descendants("externalCollection"); var allCollectionItems = new List<DynamicNode>(); if (@collectionItems != null) { allCollectionItems.AddRange(Enumerable.Cast<DynamicNode>(@collectionItems)); } if (@externalCollectionItems != null) { allCollectionItems.AddRange(Enumerable.Cast<DynamicNode>(@externalCollectionItems)); } if(@allCollectionItems.Count > 0) { <ul> @foreach (var item in @allCollectionItems) { <li><a href="@item.Url">@item.Name</a></li> } </ul> } } </umbraco:Macro>
And that works…
Basically we couldn’t get extension methods to work!
Any ideas why they don't work?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Extension Methods not working??
What it came down to is even with the right using statements etc you can’t hook into the extension methods.. is there something I’m missing?
First tried:
<umbraco:Macro runat="server" language="cshtml">
@using System.Linq
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var collectionItems = @Model.Descendants("individualCollection");
var externalCollectionItems = Model.Descendants("externalCollection");
if(@collectionItems != null && @externalCollectionItems != null)
{
var allCollectionItems = collectionItems.Cast<DynamicNode>().Union(externalCollectionItems.Cast<DynamicNode>());
if(@allCollectionItems.Any())
{
<ul>
@foreach (var item in @allCollectionItems)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}
}
}
</umbraco:Macro>
And got:
Error loading Razor Script
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Cast
Then tried:
<umbraco:Macro runat="server" language="cshtml">
@using System.Linq
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var collectionItems = @Model.Descendants("individualCollection");
var externalCollectionItems = Model.Descendants("externalCollection");
if(@collectionItems != null && @externalCollectionItems != null)
{
var allCollectionItems = collectionItems.ToArray().Cast<DynamicNode>().Union(externalCollectionItems.ToArray().Cast<DynamicNode>());
if(@allCollectionItems.Any())
{
<ul>
@foreach (var item in @allCollectionItems)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}
}
}
</umbraco:Macro>
And got:
Error loading Razor Script
'System.Array' does not contain a definition for 'Cast
Then we re-thought it... GOT THE LOGIC RIGHT as well as reduced it down and got:
<umbraco:Macro runat="server" language="cshtml">
@using System.Linq
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var collectionItems = @Model.Descendants("individualCollection");
var externalCollectionItems = @Model.Descendants("externalCollection");
var allCollectionItems = new List<DynamicNode>();
if (@collectionItems != null)
{
allCollectionItems.AddRange(Enumerable.Cast<DynamicNode>(@collectionItems));
}
if (@externalCollectionItems != null)
{
allCollectionItems.AddRange(Enumerable.Cast<DynamicNode>(@externalCollectionItems));
}
if(@allCollectionItems.Count > 0)
{
<ul>
@foreach (var item in @allCollectionItems)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
}
}
</umbraco:Macro>
And that works…
Basically we couldn’t get extension methods to work!
Any ideas why they don't work?
is working on a reply...