locked
How to Bread crumbs in webmatrix RRS feed

  • Question

  • User-1327394822 posted

    Need help with better logic...

    I used the following line to get the url segments

    var urlCollection = Request.Url.ToString().Split('/');

    Need help on how to integrate this with bootstrap breadcrumbs

    <ol class="breadcrumb">
          <li><a href="~/">Home</a></li>
          <li><a href="~/xx">xx</a></li>
          <li><a href="~/yy">yy</a></li>
          <li class="active">zz</li>
        </ol>
    <ol class="breadcrumb">
            <li><a href="~/">Atrangi Home @urlCollection.Length</a></li>
            @for(var x = 3; x < urlCollection.Length; x++){
                if(x == 3){
                    <li><a href="~/@urlCollection[x]/">@urlCollection[x]</a></li>    
                }
                else if((urlCollection.Length-2) == x){
                    <li class="active">@urlCollection[x]</li>
                }
            }
        </ol>

    The above code code works for 2 urls segments. example http://localhost:25446/paramter1/parameter2/

    I am unable to figure out a loop for any number of url segments

    Friday, April 1, 2016 11:03 PM

All replies

  • User-166373564 posted

    Hi

    for(var x = 3; x < urlCollection.Length; x++){ if(x == 3){ <li><a href="~/@urlCollection[x]/">@urlCollection[x]</a></li> } else if((urlCollection.Length-2) == x){ <li class="active">@urlCollection[x]</li> } }

    In my opinion, you need consider replacing the code snippet above with this logic:

     for( var x=0; x<urlCollection.Length; x++){.....}

    hope it helps.

    Regards,

    Angie

    Thursday, April 7, 2016 2:56 AM