I want to dynamically bind the menu item list in the master page depending upon the user login id. I'm new to MVC pattern where I get more confused by referring many sites. It will be helpful for me if u guide me to create dynamic menu. Here are the code which I have tried my best,
<script type="text/javascript">
$(document).ready(function () {
$("#accordian h3").click(function () {
$("#accordian ul ul").slideUp();
if (!$(this).next().is(":visible")) {
$(this).next().slideDown();
}
});
});
</script>
<nav class="navbar-default navbar-static-side" role="navigation">
<div id="accordian">
<ul class="nav" id="side-menu">
<li class ="nav-header">
@{
foreach (var MenuItem in Model.MainMenuModel)
{
var SubMenuItem = Model.SubMenuModel.Where(m => m.MainMenuID == MenuItem.ID);
<h3><a href="@MenuItem.MainMenuURL"> @MenuItem.MainMenuItem </a></h3>
if (SubMenuItem.Count() > 0)
{
<ul>
@foreach (var SubItem in SubMenuItem)
{
<li><a href='@SubItem.SubMenuURL'>@SubItem.SubMenuItem</a></li>
}
</ul>
}
}
}
I have business, data and services component in my project. From where I have to start to declare the menu items. Thanks in advance.