ASP.NET MVC Reusability Revisited

A few weeks ago, I wrote a post about the lack of a mechanism to seperate a unit of both logic and presentation (like a UserControl in WebForms) in ASP.NET MVC.� Well, it turns out that Rob Conery had actually come up with something called a ComponentController that took care of that, and used it in his MVC Storefront application.� (Note to self: need to catch up on those videos he’s making.)�

It actually took the removal of that feature in Preview 4 to alert me that it existed.� Not to fear, though, it’s been replaced by something called RenderAction, which will allow you to call a regular old controller action from a view like so:

<% Html.RenderAction(x=>x.MyControllerAction()) %>

Isn’t that awesome?  I sure think so.  Be warned, though, this particular feature may be even more likely to be changed than the rest of the MVC framework.  It’s part of a separate assembly called Microsoft.Web.Mvc.dll.  Stuff in there won’t be in the initial RTM, but in a future release of the framework.

Phil Haack has some reservations about this violating the purity of the MVC pattern, so I think the likelihood that this will change is close to 100%.  They’re working on some other ideas, though, so hopefully the MVC team will come up with some magic that better adheres to a mindset of separation of concerns.

For the moment, though, I’m happy!  :-)

Leave a Reply

Your email address will not be published. Required fields are marked *