connectseekers.com

Thursday, 31 March 2016

Bootstrap Style Dynamic jQuery Dropdowns Menu Using Asp.Net MVC In C#.Net

3/31/2016 - By Pranav Singh 0

This article will show you how you can create a dynamic Bootstrap style jquery menu using jquery in Asp.net MVC. This article you can use in your MVC2,MVC3,MVC4,MVC5,MVC6 applications.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication1.Models
{
    public class MenuItemListModel
    {
        public List<Menu> MenuItemList { get; set; }
    }
    public class Menu
    {
        public string MenuText { get; set; }
        public string Url { get; set; }
    }
}

Now add a controller class file and add the below code into the controller file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            MenuItemListModel menuItemModel = new MenuItemListModel();
            menuItemModel.MenuItemList = new List<Menu>();
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 1", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 2", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 3", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 4", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 5", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 6", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 7", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 8", Url = "#" });
            menuItemModel.MenuItemList.Add(new Menu { MenuText = "List Item 9", Url = "#" });
            return View(menuItemModel);
        }

    }
}

Now create a view of the action result.

@model MvcApplication1.Models.MenuItemListModel
@{
    ViewBag.Title = "Bootstrap Style Dynamic jQuery Dropdowns Menu Using Asp.Net MVC In C#.Net";
}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="../../Js/jquery.dropdown.min.js" type="text/javascript"></script>
<link href="../../Css/jquery.dropdown.css" rel="stylesheet" type="text/css" />
<a href="#" data-jq-dropdown="#jq-dropdown">Click To Open Menu</a>
<div id="jq-dropdown" class="jq-dropdown jq-dropdown-tip">
    <ul class="jq-dropdown-menu">
        @{
            int count = 1;
            foreach (var item in Model.MenuItemList)
            {
            <li><a href="@item.Url">@item.MenuText</a></li>
            if (count == 3)
            {
                <li class="jq-dropdown-divider"></li>
                count = 0;
            }
            count++;
            }
        }
    </ul>
</div>

In above code I have added dropdown.js file and .cs file to the view. Now apply loop for the model. In this I have shown item in the slot of 3 so as value become 3 it will add a devider.




About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top