The modelbinder in ASP.NET MVC is a piece of black art, converting your inputs to a nice strongly typed model. However, when binding to arrays, the DefaultModelbinder has an irritating bug. If the array is already instantiate in the model, the model binder will attempt to call .Clear() and then .Add() on the array. However arrays are fixed size lists. As a result, calling .Clear() throws a NotSupportedException as shown in the following stack trace:
UPDATE:I noticed that the problem is fixed in .NET 4.5 with the introduction of the ArrayModelBinder .
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.--System.NotSupportedException : Collection is read-only.at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)To resolve this, you can use the following model binder. It simply forces the model to null before invoking the default binder, effectively sidestepping the problem.
public class ArrayModelBinder : DefaultModelBinder { public override object BindModel( ControllerContext controllerContext, ModelBindingContext bindingContext) { var originalMetadata = bindingContext.ModelMetadata; bindingContext.ModelMetadata = new ModelMetadata( ModelMetadataProviders.Current, originalMetadata.ContainerType, () => null, //Forces model to null originalMetadata.ModelType, originalMetadata.PropertyName ); return base.BindModel(controllerContext, bindingContext); } }