9

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?

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Jesper Blad Jensen
  • 2,751
  • 17
  • 16

4 Answers4

10

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.

DevelopingChris
  • 39,797
  • 30
  • 87
  • 118
8

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

DevelopingChris
  • 39,797
  • 30
  • 87
  • 118
5

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:

http://stephenwalther.com/blog/archive/2008/08/12/asp-net-mvc-tip-31-passing-data-to-master-pages-and-user-controls.aspx

Martin Brown
  • 24,692
  • 14
  • 77
  • 122
1

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/

Matt Hinze
  • 13,577
  • 3
  • 35
  • 40