Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC Dynamic Menu System

In our current Asp.net MVC application we have 2 menu systems one accross the top and one on the left hand side. Now we have a partial view that renders the menu, however is the only way for this too work to return the menu items back with every single ViewModel? We are trying not to use the ViewData dictionary.

I think the answer to this is yes, however I want to see what others think

like image 215
LiamB Avatar asked Nov 11 '09 14:11

LiamB


People also ask

How will you implement role based authorization in MVC 5?

Choose MVC5 Controller with views, using Entity Framework and click "Add". After clicking on "Add", another window will appear. Choose Model Class and data context class and click "Add". The EmployeesController will be added under the Controllers folder with respective views.

What is partial view in ASP NET MVC?

A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.


3 Answers

3 Options:

  1. RenderAction all the way.

  2. RenderPartial as Ryan answered.

  3. An abstract MasterViewModel for example. All your out model's would inherit from this. Populated by an action filter.

like image 167
mxmissile Avatar answered Nov 15 '22 09:11

mxmissile


Are you using a Base Controller? I have found that using one, and overriding the OnActionExecuting method help me to have a central place to keep all my common page logic.

like image 22
Josh Pearce Avatar answered Nov 15 '22 08:11

Josh Pearce


You could use the Render Action from the MVC Future's library if you want to have your own controller, etc. for your menus apart from using the main view model.

like image 22
Ryan Lanciaux Avatar answered Nov 15 '22 09:11

Ryan Lanciaux