Copied to clipboard

Flag this post as spam?

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


  • strawberrylatte 34 posts 103 karma points
    Apr 27, 2021 @ 01:53
    strawberrylatte
    0

    How to set breadcrumbs with no link as static

    In my website there are some pages that have no links, but when I make breadcrumbs the pages with no links returns 404 page, I would like to make this page static instead, can anyone help?

    Below are my code so far,

    @{
                    var selection = Model.Ancestors().ToList();
                    if (selection.Any())
                    {
    
                        <ul class="breadcrumb" style="list-style-type: none; display:inline-block; margin: 0 0 3px 0;">
                            @foreach (var item in selection.OrderBy(x => x.Level))
                            {
                                var pageTitle = item.Name;
                                <li style="display: inline-block; margin: 0 10px 0 0;">
                                    <a href="@item.Url" title="@pageTitle">
                                        >   @pageTitle
                                    </a>
                                </li>
                            }
    
                        </ul>
                    }
                }
    
  • strawberrylatte 34 posts 103 karma points
    Apr 27, 2021 @ 06:17
    strawberrylatte
    0

    Anyone?

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Apr 27, 2021 @ 08:33
    Nik
    0

    Hey Strawberrylatte,

    You could do something like this:

    @{
         var selection = Model.Ancestors().ToList();
         if (selection.Any())
         {
    
             <ul class="breadcrumb" style="list-style-type: none; display:inline-block; margin: 0 0 3px 0;">
             @foreach (var item in selection.OrderBy(x => x.Level))
             {
                    var pageTitle = item.Name;
                     <li style="display: inline-block; margin: 0 10px 0 0;">
                     @if(string.IsNullOrWhiteSpace(item.Url) || item.Url == "#")
                     {
                         <text>>   @pageTitle</text>
                     }
                     else
                     {
    
                                <a href="@item.Url" title="@pageTitle">
                                    >   @pageTitle
                                </a>
                            </li>
                        }
    
                    </ul>
                }
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft