Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MuirisOG 382 posts 1284 karma points
    Jun 21, 2016 @ 10:40
    MuirisOG
    0

    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.

    Any help would be fantastic.

    Thanks,

    Muiris.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 21, 2016 @ 14:14
    Alex Skrypnyk
    0

    Hi Muiris,

    This is strange. page.Name is working fine ?

  • MuirisOG 382 posts 1284 karma points
    Jun 21, 2016 @ 14:26
    MuirisOG
    0

    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.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 21, 2016 @ 14:29
    Alex Skrypnyk
    0

    Just tested locally and its working fine. What version of Umbraco are you using?

  • MuirisOG 382 posts 1284 karma points
    Jun 21, 2016 @ 14:35
    MuirisOG
    0

    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.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 21, 2016 @ 15:01
    Alex Skrypnyk
    0

    Muiris, can you try this code:

    @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>
    }
    

    Cheers

  • MuirisOG 382 posts 1284 karma points
    Jun 22, 2016 @ 09:54
    MuirisOG
    0

    Alex,

    Many thanks for this.

    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.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 10:42
    Alex Skrypnyk
    1

    so did you solve your problem ?

  • MuirisOG 382 posts 1284 karma points
    Jun 22, 2016 @ 10:48
    MuirisOG
    0

    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!

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 10:48
    Alex Skrypnyk
    1

    I'm glad, you are welcome!

  • MuirisOG 382 posts 1284 karma points
    Jul 27, 2016 @ 11:30
    MuirisOG
    0

    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?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 22:03
    Alex Skrypnyk
    0

    Hi MuirisOG,

    Maybe if you save and publish each node again it will be fixed?

    Thanks

  • MuirisOG 382 posts 1284 karma points
    Jul 28, 2016 @ 14:07
    MuirisOG
    100

    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:

    doc.ParentId = newParentId
    cs.Save(doc, 0, False)
    

    and this code is better

    cs.Move(doc, newParentId)
    cs.SaveAndPublishWithStatus(doc)
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 28, 2016 @ 14:58
    Alex Skrypnyk
    1

    Hi,

    Great, I'm glad to help you.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft