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
I want to have some intellisense by casting my Model to DynamicNode, but once I do that I get errors. This works:
<nav> <ul> @foreach (var item in Model.AncestorOrSelf(1).Children.Where("umbracoNaviHide == false")) { <li> <a href="@item.Url" @(item.Id == Model.Id ? "class=current" : "")> @item.Name </a> </li> } </ul> </nav>
@using umbraco.MacroEngines; @{ var currentPage = (DynamicNode)Model; } <nav> <ul> @foreach (var item in currentPage.AncestorOrSelf(1).Children.Where("umbracoNaviHide == false")) { <li> <a href="@item.Url" @(item.Id == Model.Id ? "class=current" : "")> @item.Name </a> </li> } </ul> </nav>
I get an error:
'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode'
Could you remove .Children all together?
Use this :
@{ dynamic currentPage = (DynamicNode)Model; }
Instead of
@{ var currentPage = (DynamicNode)Model; }
Hmm, interesting, so if I define it as a dynamic instead of a var, I loose Intellisense. But it does work just fine indeed!
Can you try it without the cast?
@{ dynamic currentPage = Model; }
Why is this?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
AncestorOrSelf stops working when casting Model to DynamicNode
I want to have some intellisense by casting my Model to DynamicNode, but once I do that I get errors. This works:
I get an error:
'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode'
Could you remove .Children all together?
Use this :
@{ dynamic currentPage = (DynamicNode)Model; }
Instead of
@{ var currentPage = (DynamicNode)Model; }
Hmm, interesting, so if I define it as a dynamic instead of a var, I loose Intellisense. But it does work just fine indeed!
Can you try it without the cast?
@{ dynamic currentPage = Model; }
Why is this?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.