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
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.
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 Options:
RenderAction all the way.
RenderPartial as Ryan answered.
An abstract MasterViewModel for example. All your out model's would inherit from this. Populated by an action filter.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With