Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Developers,

I am creating menus and submenus using partial view and on these menus I apply roles to control access, but at the moment I'm stucked on how to add submenus on my Admin link as per my code below, I'm asking a quick help in this regard...see my code below and my Admin link should look like:
Admin
- New User
- Edit User
- Delete User

How do I go about achieving this using my code below:

enter code here

@using MvcTest.Common
@{
var menus = new[]{new { LinkText="Home",ActionName="Index",ControllerName="Home",Roles="All" },
new { LinkText="About Us",ActionName="About",ControllerName="Home",Roles="Anonymous" },
new { LinkText="Contact",ActionName="Contact",ControllerName="Home",Roles="Anonymous"},

new{LinkText="Admin",ActionName="Admin",ControllerName="Home",Roles="Administrator"},

};
}


@if (HttpContext.Current.User.Identity.IsAuthenticated == false)
{
string[] roles = MyRoleProvider.GetRolesForUser(string.Empty);
var links = from item in menus
where item.Roles.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Any(x => roles.Contains(x) || x == "All")
select item;
foreach (var link in links)
{
@:
<li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)</li>
}
}
else
{
var links = from item in menus
where item.Roles.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Any(x => new String[] { "All", "Anonymous" }.Contains(x))
select item;
foreach (var link in links)
{
@:
<li>
@Html.ActionLink(link.LinkText, link.ActionName,link.ControllerName)
</li>

}
}


Kindest Regards
Lucky

What I have tried:

I did try to research as you can see my pasted code above regarding the question!
Posted

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