DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

Nested Nav #131

Closed Aviel2000 closed 10 years ago

Aviel2000 commented 10 years ago

Hello,

Is there a way to generate the following output with BMVC?

<ul class="nav">
    <li><a href="#">Home</a></li>
    <li class="active">
        <a href="#Item">Colors</a>
        <ul class="nav">
            <li><a href="/">Red</a></li>
            <li class="active"><a href="/">Blue</a></li>
            <li><a href="/">Green</a></li>
        </ul>
    </li>
</ul>

I tried the code below but then SetLinksActiveByControllerAndAction doesn't set "Colors" active

@using (var nav = Html.Bootstrap().Begin(new Nav().Stacked().SetLinksActiveByControllerAndAction())) {
    @nav.ActionLink("Home", "Index", "Home")
    @nav.ActionLink("Colors", "Index", "Colors")
    <li>
        @Html.ActionLink("Workflows", "Index", "Workflow")
        @using (var innav = Html.Bootstrap().Begin(new Nav().SetLinksActiveByControllerAndAction())) {
            @innav.ActionLink("Red", "Index", "Red")    
            @innav.ActionLink("Blue", "Index", "Red")    
            @innav.ActionLink("Green", "Index", "Red")    
        }
    </li>           
}
DmitryEfimenko commented 10 years ago

As of now there is no easy way to do it. However, I can see how that would be useful. I'll make sure this is in the next release. It will have something like the following syntax:

@using (var nav = Html.Bootstrap().Begin(new Nav().Stacked().SetLinksActiveByControllerAndAction())) {
    @nav.ActionLink("Home", "Index", "Home")
    using(var innav = nav.SubNav("Colors").Action("Workflow/Index/").SetActiveByController())
    {
        @innav.ActionLink("Red", "Index", "Red")    
        @innav.ActionLink("Blue", "Index", "Red")    
        @innav.ActionLink("Green", "Index", "Red")
    }         
}

Let me know if you see any potential issues with this.

Aviel2000 commented 10 years ago

Excellent, the syntax is fairly intuitive. Assuming that nav.SubNav(.....) returns a type Nav, it will allow to have multiple nested Navs.

Thanks

DmitryEfimenko commented 10 years ago

this is done. Syntax a bit differs from what I wrote above. See docs