AJAX support now in ASP.Net MVC CTP 4
ASP.Net MVC CTP 4 was released in July on Codeplex (it still is not on the MS ASP.Net website yet), and I finally have some time to play with it this weekend.
Earlier this year, I was lead architect on Answerit, a social search application we helped build for 24.com. We have been toying around for a while trying to find and/or create a good MVC model in developing applications. We used the Web Client Code Factory (WCCF) for a previous project, but a broad agreement among our architects and developers at ConseQuent was that it created way too much “plumbing” coding for very little gain in sound architecture. For Answerit, we adopted a simplified version of the WCCF patterns, something that looked a lot like the MVC Framework that has been released now.
Since its release earlier this year, I’ve been playing around with the various ASP MVC CTP releases, waiting for it to mature to a point where it could handle most of the things you need to do in a large Web 2.0. project like the ones we typically do. I finally think that ASP.Net MVC has enough features in to consider doing a serious enterprise project on it (AJAX support, Master page support, output caching and something akin to user controls), and it could be time to ditch our home-grown MVC architecture.
A major reason for going for ASP.Net MVC is that it solves one of the bugbears I’ve had for a long time with ASP.Net. In ASP.Net, each page can only have one FORM tag that is automatically inserted in the page. Many of our clients at ConseQuent are large high volume web-sites, and having a web architecture where the entire page’s contents get posted back was always an uncomfortable part of the .Net web architecture. In my opinion, it was one trade-off in Microsoft’s quest to make web development as easy as WinForm development that I think should not have been made. ASP.Net MVC now makes it easy to have multiple FORM tags in a page, and for each FORM you can have a different controller action handling the callback. ASP.Net MVC CTP 4 gives two new features that make working with multiple FORM tags a whole lot easier:
AJAX.Form: AJAX.Form is a new helper method that allows you to turn a FORM tag into an AJAX “update panel”, with the submit buttons and action links now doing an AJAX callback instead of a postback. Unlike the bloated MS AJAX Update panel, which pushes the entire page’s contents back to the server, followed by calling the PageLoad event, the AJAX.Form is a lot lighter. Only data within your FORM tags get moved up the server, and only the server method you specify gets called. For more info, read Hanselman’s blog at http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx
RenderAction: Now that multiple FORM tags are allowed, it makes sense that you want to break have reusable components, much like user controls in classic ASP.Net. One of the ways ASP.Net MVC allows this is with the RenderAction method, which allows you to create actions that render subviews. When we built Answerit and a couple of other sites on our home-grown MVC pattern, we had numerous debates on user controls as to whether they should have their own controllers, or be “dumb” and live off the controller of their parent. With RenderAction, you can now support both approaches reasonably elegantly, though there is still a lot of debate whether RenderAction is true MVC or not. For more information on RenderAction, see http://blog.wekeroad.com/blog/asp-net-mvc-preview-4-componentcontroller-is-now-renderaction/
Both these new features still have some work to do (see the ASP.Net MVC Roadmap), but I am really looking forward to seeing them being rounded off and seeing ASP MVC being released. In the meanwhile, two shameless plugs:
Shameless Plug 1: Have you tried Answerit yet? If not, try it out by letting people know: Are you thinking about using ASP.Net MVC on your next project?
Shameless Plug 2: Are you a .Net developer who loves good patterns and practices (like MVC), and want to work for a company that values these as well? ConseQuent is hiring!