Posted by: Matthew | January 25, 2010

Warning: ASP.NET MVC RC FormCollection bug

UPDATE: This post refers to ASP.NET MVC 2 R1. The R2 release on 4th Feb 2010 fixed the issue.

I started to update an ASP.NET MVC 1.0 application to the new MVC 2.0 RC but will now put off that migration for now – I’ll wait for the RTM which should fix this.

The problem is to do with the FormCollection object throwing an ArgumentException (“Value cannot be null or empty”) when calling TryUpdateModel from within your controller:

at System.Web.Mvc.FormCollection.GetValue(String name) 
at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider) 
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, IValueProvider valueProvider) 

This is apparently a known issue with the RC release and should be fixed in the next release. The project I am working on is fairly sizable and with the many uses of FormCollection, a lot of runtime errors have been created!

One suggested solution is to download the MVC source code and make a fix (hack?) to by-pass the issue. However, I’d rather stay on the main MVC branch and just wait for the RTM.

Advertisement

Responses

  1. [...] to VoteWarning: ASP.NET MVC RC FormCollection bug (1/25/2010)Monday, January 25, 2010 from MatthewI started to update an ASP.NET MVC 1.0 application to the new [...]

  2. [...] So release candidate 2 (RC2) has been released. Most importantly from my point of view it fixes the breaking issue I had with RC1. From the release notes: The GetValue method of the FormCollection class now allows empty string [...]

  3. Just really love you guys… what fantastic and well researched information. Thank you bunches.


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.