MvcContrib latest release now with SubController support
One of the items that many people I know have requested are subcontrollers. Most non-trivial web applications require many things happening on a single screen. Even if it's only the current shopping cart displayed on multiple screens, the MVC Framework needs a mechanism of screen decomposition so that web applications can scale with complexity. WebForms has the Control model where markup and logic live together and can be composed easily.
With the MVC Framework CTP 5, a single action method has to make decisions for the entire screen. There are ActionFilters that can do some logic, but those are attributes, and attributes are not conducive to logic decomposition. Furthermore, ActionFilters do not work with partial views.
RenderPartial also doesn't do the job because the main view still has to know the partials.
If you haven't looked at MvcContrib's SubController support, have a look at the latest release and check out the samples. The samples show many uses for SubControllers for GETs, POSTs, and unlimited nesting of SubControllers. Each SubController has its own view, and it uses Action methods with all the same built-in dynamicism as regular controllers. In Fact, SubController inherits from Controller, so a SubController IS a Controller.
We (Headspring) are using MvcContrib SubControllers in real projects, and they are paying strong dividends.
I'm still hoping SubControllers will make it into the ASP.NET MVC Framework, but if they don't, I'm happy using this implementation.
You can follow MvcContrib on twitter. See what Matt Hinze has said about his experience with SubControllers.
Comments
Aaron Jensen said on 10.06.2008 at 11:19 AM
Maybe I'm missing something, but it appears that what you call SubControllers are not at all Controllers. Controllers have multiple actions. The SubControllers just have one named action that may as well be an Initialize method.
These appear to be analogous to MonoRail Components. Components are more explicitly *not* controllers. I think this is an important distinction. Calling them subcontrollers simply confuses people because they're *not* controllers.
Unless I'm missing something...
Jeffrey Palermo said on 10.06.2008 at 12:57 PM
@Aaron,
The named action is a convention. They support unlimited, distinct actions, just like regular Controllers. If you have a specific action name that you'd like invoked, you can certainly set that in the parent controller. I did not add that as a specific property, but it may be a good idea.
If you look at the source, you'll see "action" being set in the ControllerContext to the default one (by convention).
Because SubControllers can be used in many different pages (and Urls), the action can't be derived from the url but instead should be dictated by the parent controller.
Thanks for the observation. The explicit Action property might be a good thing to add.
tasarım said on 10.07.2008 at 3:39 PM
It really is a great contribution to the community. I also hope it will be implemented in ASP.NET MVC.
Craig Bowes said on 10.16.2008 at 11:27 AM
Maybe i'm missing something too. I'm using MVC Preview 5 and it appears you can nest controllers in a view using RenderAction:
blog.wekeroad.com/.../asp-net-mvc-pre
This lets you reuse ANY controller action on a View.
shiju varghese said on 11.08.2008 at 11:39 PM
Check the steve sanderson's solution for partial requests http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/.
It is a nice and cleaner solution.