@{ var menus = new[] { new {LinkText = "Home", ActionName = "Index", ControllerName = "Home", Roles = "All" }, new {LinkText = "About", ActionName = "Index", ControllerName = "Home", Roles = "All" }, new {LinkText = "Contact", ActionName = "Index", ControllerName = "Home", Roles = "All" }, new {LinkText = "Manage Workers", ActionName = "Index", ControllerName = "Workers", Roles = "Admin" }, new {LinkText = "Visits Manager", ActionName = "Index", ControllerName = "Visit", Roles = "Admin,Registrator,Doctor" }, new {LinkText = "Manage examinations and its prices", ActionName = "Index", ControllerName = "ExaminationDictionary", Roles = "Admin" }, new {LinkText = "Medical Examinations", ActionName = "Index", ControllerName = "MedicalExaminations", Roles = "Admin,ChiefTechnician,Technician" }, new {LinkText = "Manage visits", ActionName = "Index", ControllerName = "Visit", Roles = "Admin,Registrant,Doctor" } }; } @if (HttpContext.Current.User.Identity.IsAuthenticated) { String[] roles = System.Web.Security.Roles.GetRolesForUser(); 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) { @:
  • @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)
  • } } 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) { @:
  • @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)
  • } }