I want a dropdown menu that displays the name of all top level items in content as options. I have tried
@{
List<SelectListItem> languages= new List<SelectListItem>();
//foreach (var language in Model.Content.Siblings())
foreach (var language in CurrentPage.AncestorOrSelf(1).Siblings())
{
languages.Add(new SelectListItem
{
Text = language.Name,
Value = language.Url
});
}
@Html.DropDownList("LanguageSelect",new SelectList(languages,"Value","Text"), htmlAttributes: new { id = "LanguageSelect" });
}
which obviously doesn't work unless the user is standing at top level. Although out of all options I have looked at here this one is the only one I have gotten to give me something.
This example pulled from Umbraco.tv
@foreach (var language in CurrentPage.AncestorOrSelf(1).Siblings())
{
languages.Add(new SelectListItem
{
Text = language.Name,
Value = language.Url
});
}
doesn't give me anything. No options in the dropdown at all.
Get names of top level items in content
Hi
I want a dropdown menu that displays the name of all top level items in content as options. I have tried
which obviously doesn't work unless the user is standing at top level. Although out of all options I have looked at here this one is the only one I have gotten to give me something.
This example pulled from Umbraco.tv
doesn't give me anything. No options in the dropdown at all.
Help would be much appreciated. Thanks!
Hi Marcus,
What version of Umbraco are you using?
Hello. Umbraco version 7.2.5 assembly: 1.0.5610.18894 :)
Great ))
This code works for me :
Thanks, Alex
I haven't fully tested it, but it does indeed appear to work!
Thank you for your help!
is working on a reply...