breadcrumbs - Template v PartialViewMacro in Webforms site
I'm having trouble with the OrderBy in my PartialViewMacro in my WebForms website (umbraco version 743)
This works in the template:
<umbraco:Macro runat="server" language="cshtml">
@if (Model.Ancestors().Any())
{
<div id="breadcrumbs" class="btn-group btn-breadcrumb">
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var page in Model.Ancestors().OrderBy("Level"))
{
if (page.Parent != null){
<a class="btn btn-default" href="@page.Id">@page.Name</a>
} else {
<a href="@page.Id" class="btn btn-default"><i class="fa fa-home" aria-hidden="true"></i><span class="sr-only">Home</span></a>
<div class="btn btn-default ellipsis">...</div>
}
}
@* Display the current page as the last item in the list *@
<div class="btn btn-default disabled">@Model.Name</div>
</div>
}
</umbraco:Macro>
but this doesn't work in a Partial View Macro:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if (CurrentPage.Ancestors().Any())
{
<div id="breadcrumbs" class="btn-group btn-breadcrumb">
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var page in CurrentPage.Ancestors().OrderBy("Level").Where("Visible"))
{
if (page.Parent != null){
<a class="btn btn-default" href="@page.Id">@page.Name</a>
} else {
<a href="@page.Id" class="btn btn-default"><i class="fa fa-home" aria-hidden="true"></i><span class="sr-only">Home</span></a>
<div class="btn btn-default ellipsis">...</div>
}
}
@* Display the current page as the last item in the list *@
<div class="btn btn-default disabled">@CurrentPage.Name</div>
</div>
}
I've output the value from @page.Level to check it, and it is "2" for all levels above 1, even when it should be 3 or higher.
I installed it in Visual Studio using nuget, a process I have done since early in version 6 (I'm keeping pace with developments while migrating a large-ish set of sites from an older CMS - a project that has me very busy).
I create a docType and import the content from the old CMS - a process I have been refining.
@if (Model.Ancestors().Any())
{
<div id="breadcrumbs" class="btn-group btn-breadcrumb">
@* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
@foreach (var page in Model.Ancestors().Where(x => x.IsVisible()).OrderBy(x => x.Level))
{
if (page.Parent != null)
{
<a class="btn btn-default" href="@page.Id">@page.Name</a>
}
else
{
<a href="@page.Id" class="btn btn-default"><i class="fa fa-home" aria-hidden="true"></i><span class="sr-only">Home</span></a>
<div class="btn btn-default ellipsis">...</div>
}
}
@* Display the current page as the last item in the list *@
<div class="btn btn-default disabled">@Model.Name</div>
</div>
}
Unfortunately, it generated the following error when I used it in my usercontrol:
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type at System.Web.Compilation.AssemblyBuilder.Compile()
However, before I tried your code, I tried the previous version one more time, and strangely, this time it listed the breadcrumbs in the correct order.
Perhaps there's a cache somewhere that retains the breadcrumbs.
it seems to have resolved itself without any real input from me - just leaving it overnight seemed to do the trick.
I'm used to clearing every cache in ASP.NET but must admit to not doing it yesterday (I did clear the Umbraco caches) but if I hit something like this again, I will.
Hi Alex,
I've no idea why the breadcrumbs now appear in the correct order, but now I've noticed another problem.
The "level" is wrong in the umbracoNode table (and in the cmsContentXml table). The parentID is correct, but the path is wrong - it is missing the parent's parent, if that makes sense.
This problem doesn't occur with all pages in the CMS, but where it does, the CMS Editor collapses the tree so I have to traverse the tree again to find the page I want to edit.
It may be because I reassigned parent Ids and this process could have been interrupted.
Is there any way (either in the CMS or programatically) to rebuild the path and the level based on the parentId?
I had reassigned the parents to all pages in the CMS after performing an import from another CMS product, but I can see now that this code, in VB, although it works, is the wrong option:
breadcrumbs - Template v PartialViewMacro in Webforms site
I'm having trouble with the OrderBy in my PartialViewMacro in my WebForms website (umbraco version 743)
This works in the template:
but this doesn't work in a Partial View Macro:
I've output the value from @page.Level to check it, and it is "2" for all levels above 1, even when it should be 3 or higher.
Any help would be fantastic.
Thanks,
Muiris.
Hi Muiris,
This is strange. page.Name is working fine ?
Thanks Alex,
Yes, @page.Name is working fine.
I've tried outputting the @page.Level using the template version and the macro and it always seems to be 2.
I thought it might be something to do with using webforms.
I'm now trying the same code in a usercontrol to see if it makes a difference, but it seems to me that it isn't picking up the level correctly.
Just tested locally and its working fine. What version of Umbraco are you using?
I'm working on version 743.
I installed it in Visual Studio using nuget, a process I have done since early in version 6 (I'm keeping pace with developments while migrating a large-ish set of sites from an older CMS - a project that has me very busy).
I create a docType and import the content from the old CMS - a process I have been refining.
Muiris, can you try this code:
Cheers
Alex,
Many thanks for this.
Unfortunately, it generated the following error when I used it in my usercontrol:
However, before I tried your code, I tried the previous version one more time, and strangely, this time it listed the breadcrumbs in the correct order.
Perhaps there's a cache somewhere that retains the breadcrumbs.
so did you solve your problem ?
Yes Alex,
it seems to have resolved itself without any real input from me - just leaving it overnight seemed to do the trick.
I'm used to clearing every cache in ASP.NET but must admit to not doing it yesterday (I did clear the Umbraco caches) but if I hit something like this again, I will.
The breadcrumbs now appear in the order I expect.
Many thanks for all your help!
I'm glad, you are welcome!
Hi Alex, I've no idea why the breadcrumbs now appear in the correct order, but now I've noticed another problem.
The "level" is wrong in the umbracoNode table (and in the cmsContentXml table). The parentID is correct, but the path is wrong - it is missing the parent's parent, if that makes sense.
This problem doesn't occur with all pages in the CMS, but where it does, the CMS Editor collapses the tree so I have to traverse the tree again to find the page I want to edit.
It may be because I reassigned parent Ids and this process could have been interrupted.
Is there any way (either in the CMS or programatically) to rebuild the path and the level based on the parentId?
Hi MuirisOG,
Maybe if you save and publish each node again it will be fixed?
Thanks
Hi Alex
thanks, that solved the problem.
I had reassigned the parents to all pages in the CMS after performing an import from another CMS product, but I can see now that this code, in VB, although it works, is the wrong option:
and this code is better
Hi,
Great, I'm glad to help you.
Thanks
is working on a reply...