Blog Home  Home RSS 2.0 Atom 1.0 CDF  
CLYDE BARRETTO's BLOG - .NET etc. - ASP.NET MVC 2 RC (evaluating)– EDIT controller bug related to UpdateModel and ValueProvider
Visual Studio/.NET/Smart Client/SharePoint
 
 Monday, February 01, 2010

We were evaluating ASP.NET MVC 2 RC. As a detour instead of creating the regular NerdDinner web application, We decided to hook up the MVC application to our own database with some legacy data. We created the MODEL and related CONTROLLERS and VIEWS for actions view,create successfully.

We ran into trouble while implementing EDIT feature....We first created the related Controller then the View. When we tested the application – there were no errors thrown – except that NO UPDATES were being made to the database. After setting breakpoints etc. the error was being thrown when we were using UpdateModel to update the model with the FormCollection.ToValueProvider statement.

Offending Code in public ActionResult Edit(int id, FormCollection collection) {Initialization Code here.....then...UpdateModel(yourmodelinstance, collection.ToValueProvider())

Error Thrown: "Value cannot be null or empty.\r\nParameter name: name"

Change to : UpdateModel(yourmodelinstance)

We first checked if there was something wrong in our implementation and after sometime decide that is was not necessarily our model \implementation that was causing the issue. The issue lies in MVC 2 RC framework – please review links below – per MS this will be fixed in the next code drop. In the mean time leave out the 2’nd parameter of the UpdateModel call as suggested by the article – this works.

http://forums.asp.net/p/1514421/3620957.aspx

The reason I am writing this post is that it took quite a bit of time to debug the problem – and searching the forums\internet did not easily yield any helpful articles – hope this helps.

There is also another post where someone has actually fixed the MVC Open Source to fix the core problem - although I cannot vouch if this is a long term solution - if you are interested here is the link ...http://blogs.victorero.com/. We will wait for the next MVC update, as we are not using this in production currently.

2/1/2010 2:29:47 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]   .NET 2.0 | ASP.Net | MVC | Visual Basic \ VB.Net | Visual C# | Visual Studio 2008  | 
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2012 Clyde Barretto. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: