May 2009 Entries

Iterating on an ASP.NET MVC Model Binder

After my last post on model binding tips I’ve had a number of questions about the nuances of model binding. Let’s work through a sample. Imagine you have a Recipe class that can hold all the information you need to make Love Mussels, and now you've decided to build a model binder to bind and validate recipes.  Iteration 1 Let’s start with the naive approach. This code has a number of problems. public class RecipeModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var...