I am adapting the NonClassModels area of Brad Wilson's Advanced MVCConf2011 project. Everything works fine for me when my dictionary is <string,string> but when I change it to <string,object> I get an error in my call to
OnModelUpdated(controllerContext, bindingContext); within the DictionaryModelBinder.
The error is
Unable to cast object of type 'System.String[]' to type 'System.String'.
[InvalidCastException: Unable to cast object of type 'System.String[]' to type 'System.String'.] System.ComponentModel.DataAnnotations.StringLengthAttribute.IsValid(Object value) +46 System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext) +115 System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext) +29 System.Web.Mvc.<Validate>d__1.MoveNext() +161 System.Web.Mvc.<Validate>d__5.MoveNext() +311 System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) +136 MvcConf2011.Areas.NonClassModels.DictionaryModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in c:\Projects\EnterpriseManagementSamples\advanced-mvc-3 - Copy\Areas\NonClassModels\Utility\ModelBinder\DictionaryModelBinder.cs:51
Any ideas? I have not been able to successfully get the source code into the project to debug it.
Add your 2¢