Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 30, 2012 12:35 AM by eric2820
Member
155 Points
172 Posts
Nov 29, 2012 11:49 PM|LINK
I wish to enable this menu only if the logged in user is an administrator. I am not sure how to do it, and I can't seem to find a sample code online. Can someone help, please?
@(Html.Telerik().Menu() .Name("Administrator") .Orientation(MenuOrientation.Vertical) .Items(item => item.Add() .Text("Manager") .Enable(false) .HtmlAttributes( new {style="text-align:left"}) .Action("Index", "Users") })
Contributor
2777 Points
1161 Posts
Nov 30, 2012 12:35 AM|LINK
If you render the menu as a PartialView it gets easy to do from the controller.
[Authorize] public PartialViewResult AdminNav( string MemberName ) { if ( User.Identity.Name == "Admin" ) { // this case intentailly left empty } else return null;
List<Menu> menu = new List<Menu>(); menu.Add( new Menu( "Home", "Index", "AdminBackOffice", null ) ); menu.Add( new Menu( "Create Blog", "CreateBlog", "AdminBackOffice", null ) ); menu.Add( new Menu( "Create Msgs", "CreateAutoresponderMsgs", "AdminBackOffice", null ) ); menu.Add( new Menu( "Enter Bank Info", "BankInfo", "AdminBackOffice", null ) ); menu.Add( new Menu( "Change Passwords", "ChangePasswords", "AdminBackOffice", null ) ); menu.Add( new Menu( "Service Requests", "ServiceRequests", "AdminBackOffice", null ) ); menu.Add( new Menu( "View Logins", "ViewLogins", "AdminBackOffice", null ) ); menu.Add( new Menu( "View Errors", "ViewErrors", "AdminBackOffice", null ) ); menu.Add( new Menu( "Log Off", "LogOut", "BackOffice", MemberName ) ); return PartialView( menu ); }
gagouche
Member
155 Points
172 Posts
Enable Menu Based on Roles
Nov 29, 2012 11:49 PM|LINK
I wish to enable this menu only if the logged in user is an administrator. I am not sure how to do it, and I can't seem to find a sample code online. Can someone help, please?
@(Html.Telerik().Menu() .Name("Administrator") .Orientation(MenuOrientation.Vertical) .Items(item => item.Add() .Text("Manager") .Enable(false) .HtmlAttributes( new {style="text-align:left"}) .Action("Index", "Users") })Gagouche
eric2820
Contributor
2777 Points
1161 Posts
Re: Enable Menu Based on Roles
Nov 30, 2012 12:35 AM|LINK
If you render the menu as a PartialView it gets easy to do from the controller.
[Authorize]
public PartialViewResult AdminNav( string MemberName )
{
if ( User.Identity.Name == "Admin" )
{
// this case intentailly left empty
}
else
return null;
List<Menu> menu = new List<Menu>();
menu.Add( new Menu( "Home", "Index", "AdminBackOffice", null ) );
menu.Add( new Menu( "Create Blog", "CreateBlog", "AdminBackOffice", null ) );
menu.Add( new Menu( "Create Msgs", "CreateAutoresponderMsgs", "AdminBackOffice", null ) );
menu.Add( new Menu( "Enter Bank Info", "BankInfo", "AdminBackOffice", null ) );
menu.Add( new Menu( "Change Passwords", "ChangePasswords", "AdminBackOffice", null ) );
menu.Add( new Menu( "Service Requests", "ServiceRequests", "AdminBackOffice", null ) );
menu.Add( new Menu( "View Logins", "ViewLogins", "AdminBackOffice", null ) );
menu.Add( new Menu( "View Errors", "ViewErrors", "AdminBackOffice", null ) );
menu.Add( new Menu( "Log Off", "LogOut", "BackOffice", MemberName ) );
return PartialView( menu );
}
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.