Dropdownlist Menu ASP.NET MVC 5

1

I need to change the menu to apply a Dropdownlist, but I'm having difficulty. I'm following the steps of the bootstrap site, but when you click the submenu does not appear, follow the code below:

<body>
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="../../Home/Index"><img src="~/Images/logo_Web.png" width="50" height="50" /></a>
        </div>
        <div class="navbar-collapse collapse">
            @if (Session["PerfilUsuario"] != null)
            {
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Chamados <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li>@Html.ActionLink("Novo Chamado", "Create", "Chamado")</li>
                            <li>@Html.ActionLink("Acompanhar Chamados", "Index", "Chamado")</li>
                            @if (Session["PerfilUsuario"].ToString().Equals("1") || Session["PerfilUsuario"].ToString().Equals("3")|| Session["PerfilUsuario"].ToString().Equals("5")|| Session["PerfilUsuario"].ToString().Equals("6")){
                                <li>@Html.ActionLink("Chamados Encerrados", "ChamadosEncerrados", "Chamado")</li>
                            }
                        </ul>
                    </li>

                    @if (Session["PerfilUsuario"].ToString().Equals("1"))
                    {
                        <li>@Html.ActionLink("Obras", "Index", "Obra")</li>
                    }
                    @if (Session["PerfilUsuario"].ToString().Equals("1") || Session["PerfilUsuario"].ToString().Equals("6"))
                    {
                        <li>@Html.ActionLink("Setores", "Index", "Setor")</li>
                    }
                </ul>
            }
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - Chamados BRA</p>
    </footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

    
asked by anonymous 24.09.2015 / 21:30

2 answers

1

After putting the script below the menu worked.

<script>
    $(document).ready(function () {
        $('.dropdown-toggle').dropdown();
    });
</script>
    
25.09.2015 / 14:31
1

There is no problem with your code. probably should the conditions in their if's not being fulfilled. Remove these checks, and test your menu without them.

Test your code like this:

<body>
<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="../../Home/Index"><img src="~/Images/logo_Web.png" width="50" height="50" /></a>
        </div>
        <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Chamados <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li>@Html.ActionLink("Novo Chamado", "Create", "Chamado")</li>
                            <li>@Html.ActionLink("Acompanhar Chamados", "Index", "Chamado")</li>
                                <li>@Html.ActionLink("Chamados Encerrados", "ChamadosEncerrados", "Chamado")</li>
                        </ul>
                    </li>
                        <li>@Html.ActionLink("Obras", "Index", "Obra")</li>
                        <li>@Html.ActionLink("Setores", "Index", "Setor")</li>
                </ul>
            @Html.Partial("_LoginPartial")
        </div>
    </div>
</div>
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - Chamados BRA</p>
    </footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

If it still does not work, check the console of your browser (F12) if you have any errors.

Look at the result of your menu here.

    
25.09.2015 / 01:01