This question is locked. New answers and comments are not allowed.
I want to know if it's possible to dynamically create a Menu. So, if I have two different users with different permissions, one user might be able to see a part of the system that the other user cannot. But, all examples I've seen hard code the Menu e.g.
So, could if user 1 has permission to see "Jobs", but user 2 doesn't, I'd need to remove the "Jobs" menu item. How would I go about doing this programmatically, and by this I mean generate the menu according to permissions?
@(Html.Telerik().Menu()
.Name("menu")
.Items(menus =>
{
menus.Add().Text("Clients").Action("Index", "Clients");
menus.Add().Text("Jobs").Items(submenu =>
{ // etc.
So, could if user 1 has permission to see "Jobs", but user 2 doesn't, I'd need to remove the "Jobs" menu item. How would I go about doing this programmatically, and by this I mean generate the menu according to permissions?
7 Answers, 1 is accepted
0
Stephen
Top achievements
Rank 1
answered on 29 May 2012, 03:32 PM
Hello,
I am looking to do the same thing. I have done this before with the RadMenu in .net forms, but I'm not sure how to do this in MVC....
thanks,
Steve
I am looking to do the same thing. I have done this before with the RadMenu in .net forms, but I'm not sure how to do this in MVC....
thanks,
Steve
0
dani
Top achievements
Rank 1
answered on 01 Jun 2012, 09:30 AM
Same Problem here, How do I conditionally show more menu items to an authorized user.... ?
0
Aleksander
Top achievements
Rank 1
answered on 05 Jun 2012, 04:59 PM
ditto?
0
Virgilio Esteves
Top achievements
Rank 1
answered on 14 Jun 2012, 08:57 AM
If you bind the menu data to a Model, you'll be able to filter the data anyway you want. I cannot provide you a sample right now, but if you really need it, I may release it later today.
Regards,
Virgilio
Regards,
Virgilio
0
Stephen
Top achievements
Rank 1
answered on 15 Jun 2012, 01:50 PM
Hello,
I am new to MVC so some sample code would be extremely helpful and greatly appreciated.
Thanks,
Steve
I am new to MVC so some sample code would be extremely helpful and greatly appreciated.
Thanks,
Steve
0
Bruce
Top achievements
Rank 1
answered on 20 Jun 2012, 06:53 PM
I have seen the example that Telerik uses Northwind to bind the model. The issue for me is that you are using Entity Framework (it appears) and I would like to use dbml's tied to Stored procedures. I have a table of menu items and a table of submenu items. It appears that the EF create two ienumerables and I would like to be able to bind the model so that I can have Menu items and submenu items. The reason I want to build it dynamically is because each user based on security profiles will be presented with a different menu. So building dynamicaly based on a database tables is pretty important for us. Any code examples would be deeply appreciated.Thank you, Bruce.
0
Peter Shaw
Top achievements
Rank 1
answered on 02 Jul 2012, 02:43 PM
If it's any help, here's how I do it in razor:
In my _Layout.cshtm file where the menu is to appear ---->
@RenderSection("menu", false)
then in the view where I need to change the menu (or provide a different one)
@section menu
{
@(Html.Telerik().Menu()
.Name("menu")
.Items(menu =>
{
menu.Add().Text("Home").Action("Index", "Home");
menu.Add().Text("Jobs").........
//More items here
}))
}
The good part is, you can if you wish leave the menu out entirely, and it won't be drawn at all, or you can define a menu section on a page by page basis, as well as having a number of standard menus that you could define as razor partial views and include them in any given section you need.
In my _Layout.cshtm file where the menu is to appear ---->
@RenderSection("menu", false)
then in the view where I need to change the menu (or provide a different one)
@section menu
{
@(Html.Telerik().Menu()
.Name("menu")
.Items(menu =>
{
menu.Add().Text("Home").Action("Index", "Home");
menu.Add().Text("Jobs").........
//More items here
}))
}
The good part is, you can if you wish leave the menu out entirely, and it won't be drawn at all, or you can define a menu section on a page by page basis, as well as having a number of standard menus that you could define as razor partial views and include them in any given section you need.