Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap dropdown menu not working within _Layout.cshtml Shared in MVC 4

I am attempting to implement a dropdown menu in my shared _Layout and am unfortunately not successful.

Do you guys know what the issue is here:

    <nav>
        <div class="dropdown">
            <button class="btn" data-toggle="dropdown"> This that </button>
            <ul class="dropdown-menu">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
            </ul>
        </div>
    </nav>

When I do display: block on my ul I can see the drop down, however in the above case when I click the button nothing drops down.

like image 516
NoviceDeveloper Avatar asked Mar 16 '26 17:03

NoviceDeveloper


2 Answers

Here is my workaround in case someone was still looking for.

   .dropdown:hover .dropdown-menu {display: block;}

   .nav-tabs .dropdown-menu, .nav-pills .dropdown-menu, .navbar .dropdown-menu
     {margin-top: 0;}    
like image 191
NoviceDeveloper Avatar answered Mar 19 '26 00:03

NoviceDeveloper


this may be useless now. but i wanted to share what the actual problem was.

I faced the same problem. the problem is importing both the normal and minified versions of bootstrap css files.

//wrong way

<link href="@Url.Content("~/Content/themes/vendor/bootstrap.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/themes/vendor/bootstrap-theme.min.css")" rel="stylesheet" />
 <link href="@Url.Content("~/Content/themes/vendor/bootstrap.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/themes/vendor/bootstrap-theme.css")" rel="stylesheet" />

//right way

<link href="@Url.Content("~/Content/themes/vendor/bootstrap.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/themes/vendor/bootstrap-theme.min.css")" rel="stylesheet" />
like image 38
sanjith edward Avatar answered Mar 19 '26 00:03

sanjith edward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!