Search code examples
asp.net-mvcaction-filter

Render different menus using ASP.NET MVC ActionFilters


I have a standard menu using ul and li tags. And in my database, I have a table Users with a field 'certificate' and depending the value of this 'certificate', the user will see or not some items of the menu.

I was reading some texts and I think I will have to use ActionFilters. Is this right?

So, how can I render different menus depending which user is accessing?

thanks!!


Solution

  • Check out the Html.RenderAction methods that the futures assembly introduces. They can let you, in a very clean fashion, render an action method. This means that you can have a MenuController (for example) that takes care of all of the logic about what menu items you can render. Then it can just pass a simple data structure to the view, whose responsibility it is to render that data structure. Very clean.