Click here to Skip to main content
14,928,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im creating drop-down menu using C# .net MVC in the navbar i add this code in my layout view html page

    <div class="navbar nav-justified 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>
                @Html.ActionLink("Karan", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">

                    <li>@Html.ActionLink("Courses", "Courses", "Home")</li>

                    <div class="dropdown">
                        <button onclick="myFunction()" class="dropbtn">Dropdown</button>
                        <p id="myDropdown" class="dropdown-content">
                            <a href="#">Link 1</a>
                            <a href="#">Link 2</a>
                            <a href="#">Link 3</a>
    <div class="container body-content">
        <hr />
            <p>&copy; @DateTime.Now.Year - Karan Tutorials</p>

    @RenderSection("scripts", required: false)

and i add javascript with the name dropdown.js

function myFunction() {

// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
    if (!'.dropbtn')) {

        var dropdowns = document.getElementsByClassName("dropdown-content");
        var i;
        for (i = 0; i < dropdowns.length; i++) {
            var openDropdown = dropdowns[i];
            if (openDropdown.classList.contains('show')) {

but its not working whats my fouls or whats wrong with the code any one help me?

What I have tried:

I am trying to Create drop-down menu using C# .net MVC in the navbar I add the above code in my layout view html page and also above javascript code but its not working for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900