I'm an old ASP.NET Web Forms developer that is really rusty and trying to give MVC, Razor and Bootstrap a go.
In my _Layout.cshtml file I have a Hello World menu. I would like to enable/disable menu items based upon the security of the login user.
Since the menu is being created with server side logic and I am getting determining whether a menu item is available based on info from the Active Directory and that is also on the server, I am thinking that I could have a server side common routine enable or disable menu items based on membership or lack of membership to a global group.
Taking the default auto generated MVC _Layout.cshtml file and simply adding a dropdown "Tools" item, how can I pro grammatically disable a menu as described above? I'm thinking that I'd like to programmatically add a "Disabled" class and set the href property to # to make it unclickable if the user was not allowed to access that function.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<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>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tools<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="disabled">
<a href="#">Show me the Contact Page</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="@Url.Action("About", "Home")">Show me the About Page!</a>
</li>
</ul>
</li>
</ul>
<p class="nav navbar-text navbar-right">Hello, @User.Identity.Name!</p>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
Sorry for being a noob