Copied to clipboard

Flag this post as spam?

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


  • David Tregoning 63 posts 236 karma points
    Jan 22, 2014 @ 16:27
    David Tregoning
    0

    Razor breadcrumb script outputting in reverse

    My current content structure is as follows:

    • Home
      • About Us
        • Our people
          • John

    I am using the code snippet for constructing a breadcrumb in razor from the umbraco reference site (have commented out the current page name to simplify results in this example) as I am new to Razor:

    <ul>
    @foreach (var ancestor in CurrentPage.Ancestors().Where("Visible"))
      {
        <li><a href="@ancestor.Url">@ancestor.Name</a></li>
      }
    @* <li>@Model.Content.Name</li> *@
    </ul>
    

    When I view the John page of my site my breadcrumb renders as follows:

    I am seeing what I would expect to which is a list built from the parent (Ancestor) of the current page, then the parent (Ancestor) of the that page and so on until there are no more parents (ancestors) to find, ie. the root of the site.

    However I would prefer my list items to be in the opposite order (as a normal breadcrumb), then the @Model.Content.Name line can be uncommented to display the following breadcrumb

    Can somebody explain why my breadcrumb is not rendering as per other examples that use the same razor script?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 22, 2014 @ 17:13
    Fuji Kusaka
    4

    Hi David,

    Can you try this

    <ul>
    @foreach (var ancestor in CurrentPage.Ancestors().Where("Visible").OrderBy("Level"))
      {
       
    <li><ahref="@ancestor.Url">@ancestor.Name</a></li>
      }
    @*
    <li>@Model.Content.Name</li> *@
    </ul>
  • David Tregoning 63 posts 236 karma points
    Jan 22, 2014 @ 17:49
    David Tregoning
    0

    Thats great Fuji, I did see an example on searching the internet but they had:

    @foreach (var ancestor in CurrentPage.Ancestors().OrderBy("Level").Where("Visible"))
    

    Which did not work as opposed to:

    @foreach (var ancestor in CurrentPage.Ancestors().Where("Visible").OrderBy("Level"))
    

    Thanks

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 22, 2014 @ 17:54
    Fuji Kusaka
    1

    Good if you got it working :)

  • Manikandan 15 posts 96 karma points
    Nov 25, 2015 @ 08:28
    Manikandan
    0

    Thank you Fuji.......

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 25, 2015 @ 08:41
    Fuji Kusaka
    0

    :)

Please Sign in or register to post replies

Write your reply to:

Draft