ASP.NET MVC Reusability Revisited

Published 7/18/2008 by Brian

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<MyController>(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!  :-)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Brian Sullivan

From one geek to another...