ASP.NET MVC "Components" ASP.NET MVC "Components" asp.net asp.net

ASP.NET MVC "Components"


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.


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


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