Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
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.
Remember Me