I have the following development code for creating various sub menus, to meet certain requirements.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var childPages = Model.Content.Children;
var ancestors = Model.Content.Ancestors();
var ancestorsOrSelf = Model.Content.AncestorOrSelf();
}
<ul>
@foreach(var item in childPages)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
<ul>
@foreach(var item in ancestors)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
<ul>
@foreach(var item in ancestorsOrSelf)
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
The code above give the following error for ancestorOrSelf variable:
CS1579: foreach statement cannot operate on variables of type 'Umbraco.Core.Models.IPublishedContent' because 'Umbraco.Core.Models.IPublishedContent' does not contain a public definition for 'GetEnumerator'
I believe Model.Content.AncestorOrSelf() is not an IEnumerable, try using AncestorsOrSelf() instead (notice the difference between Ancestor and Ancestors).
sub menu creation error
Dear Umbraco Team
I have the following development code for creating various sub menus, to meet certain requirements.
The code above give the following error for ancestorOrSelf variable:
any reason why am i missing something simple ?
Thanks Dibs
Looks like your variable declared is not of the list type. You also need to specify which node the iteration should be looking at.
Hi Eric
ancestors variable works and is not declared as a list type
thanks Dibs
Hi Dibs,
I believe Model.Content.AncestorOrSelf() is not an IEnumerable, try using AncestorsOrSelf() instead (notice the difference between Ancestor and Ancestors).
B.
Cheers Bijesh
Thanks for the reply, i see my typo was to blame : (
Thanks Dibs
No worries, glad to be of help :)
B.
is working on a reply...