April 2009 Entries

6 Tips for ASP.NET MVC Model Binding

Model binding in the ASP.NET MVC framework is simple. Your action methods need data, and the incoming HTTP request carries the data you need. The catch is that the data is embedded into POST-ed form values, and possibly the URL itself. Enter the DefaultModelBinder, which can magically convert form values and route data into objects. Model binders allow your controller code to remain cleanly separated from the dirtiness of interrogating the request and its associated environment.    Here are some tips on how to take advantage of model binding in your MVC projects. Tip #1: Prefer Binding Over...

Life and Times of an ASP.NET MVC Controller

The May issue of MSDN Magazine is now on-line with my article “The Life and Times of an ASP.NET MVC Controller”. In this article, I will dissect the ASP.NET MVC framework and look at how controllers work. I'll explain how the framework interacts with your controllers and how you can influence those interactions. I'll look at controller factories, controller actions, action filters, and action results as well. I don’t like programming by coincidence, and I hope this article gives you everything you need to work confidently with MVC controllers. In addition to the technical details, I also believe...

ASP.NET MVC Controls and Good versus Evil

Luis and David recently posted about the controls that appear in the ASP.NET MVC Futures 1.0 release. Luis Abreu: The MVC framework: the Repeater control David Hayden: ASP.NET MVC Controls in ASP.NET MVC Futures - Repeater Control Example I’ve seen some discussions where people positively erupt at any mention of the word “control” in an MVC setting. These are the people who consider ASP.NET Web Forms as the ultimate source of evil in the universe – a cross between a Sith lord and a velociraptor. The idea of introducing controls, with un-testable event handling code and giant...

MVC Course is Coming Online!

Just a quick note to let you know that the first three modules of my ASP.NET MVC course are ready for consumption at Pluralsight! On-Demand. Pluralsight is building a fantastic library of online content you can view as a subscriber, or see in person via instructor led training at a classroom or on-site at your place. There is also a heap of free screencasts and previews to wet your appetite. A single subscription can get you access to training for WPF, C#, .NET, ASP.NET, AJAX, WF, WCF, Silverlight, BizTalk, with more on the way. P.S. I’ve heard the...

Putting the M in MVC – Part III

In the last post we talked about using entities as the models in an MVC application. This approach works well until an application reaches a certain level of complexity, at which point entities as the M in MVC can become painful. I believe entities exist to serve the business layer. They also have a role in the data access layer, but only because the data access layer has to be acutely aware of entities. The reverse is not true – entities don’t need to know details about the data access layer nor how they are saved in persistent storage....

Putting the M in MVC – Part II

Rob just put the M into MVC using Subsonic and a Subsonic MVC Template. The template allows you to go from 0 to functioning application in less time than it takes to listen to a Rob Zombie song. Fantastic work by Rob C, and it leads nicely into the actual question behind this series of posts: “I have created domain entities like Customer, Order, etc. They come out of  repository classes backed by NHibernate. I’m wondering if I send them directly to the view or if I create a ViewModel class to hold data. I’m confused by all...

Euphemized Exceptions for .NET 4.0

Microsoft has discovered, after several well-funded studies, that the names they use for exceptions in the .NET framework create pathological levels of anxiety and stress in programmers. Thus, for .NET 4.0 they decided to create a “kinder and gentler” version of .NET by renaming exceptions in the framework class library. The changes I know about so far: ArgumentException becomes a DifferenceOfOpinionException BadImageFormatException becomes a AestheticallyChallengedException InvalidCastException becomes a CasteDiscriminationException AbandonedMutexException becomes a SingleAndLookingMutexException OverflowException becomes a TooBigButStillFailedException InvalidOperationException becomes a JustSayNoExceptionUnfortunately,  we will need to update and recompile our code for .NET 4.0, but imagine the healthier lifestyle that will...