Is there someway to have a part of the page that renders like a little sub-page, like components?
For example, if I have a shopping cart on all my pages?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Using preview 5, Html.RenderPartial is your man, you can render sub-controls, and pass them your viewdata, or an arbitrary model, and new viewdata combo.
Method 2
If you want it to render another controllers action, as a component, to get encapsulation, you use.
Html.RenderAction
uses routedata to get you there, has its own viewdata and kind of mini life cycle
Method 3
You can create an ActionFilter that modifies the view data. That way, you can decorate every action that returns the partial with the action filter. Take a look at my post:
Method 4
You are looking for subcontrollers. This implementation is the best way to do what you are talking about.
Edit: I just posted about this here: http://mhinze.com/subcontrollers-in-aspnet-mvc/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0