At work, we have a web application implemented using the ASP.NET MVC Framework. This week, I upgraded that site from MVC beta to MVC Release Candidate. The release notes had some important information about editing the web.config so that you don't need a code-behind for your views, but all it tells you about upgrading the rest of your code-base is that you should upgrade the MVC assemblies that your application is referencing and then fix the compiler errors. Even after reading about the various changes in the RC, I still had a little trouble figuring out how to adapt our code to work with the various breaking changes, so I figured I would outline some of the issues I ran into here, and how I resolved them, to save you some time if you haven't gotten around to doing this upgrade yet. Here goes...
- ModelBinderResult no longer exists. BindModel() should now take a ControllerContext as well as a ModelBindingContext parameter, and it should return the model itself, rather than wrapping it in a ModelBinderResult
- IValueProvider went away - use FormCollection instead to retrieve form values
- The value provider parameter to UpdateModel is now of type IDictionary<string, ValueProviderResult>, rather than IValueProvider (since IValueProvider no longer exists). You must call ToValueProvider() on your FormCollection and pass that to UpdateModel.
- ModelBindingContext no longer has a "Controller" property. If you're trying to access that from the BindModel method in a model binder, access it from the new ControllerContext parameter instead.
- ModelBindingContext.ValueProvider is now of type IDictionary<string, ValueProviderResult> (not IValueProvider since that no longer exists), so any places where you're calling GetValue() on that, you will need to replace it with a call to the indexer (eg. bindingContext.ValueProvider[fieldName] instead of bindingContext.ValueProvider.GetValue(fieldName)). Also note that when you attempt to obtain a value from a generic Dictionary for a key that does not exist, you will get a KeyNotFoundException, whereas GetValue() simply returned null, so you will need to add a check that the key exists before retrieving a value from the collection.
- The ModelBindingContext constructor now takes zero arguments instead of seven. If you're instantiating a ModelBindingContext in a unit test, rather than passing everything in on the constructor, you'll want to set
the ValueProvider, ModelType and Model properties (the controller is no longer set on the ModelBindingContext - its set in the ControllerContext, and all the other constructor parameters we were passing null for). - RedirectToRouteResult.Values is now RedirectToRouteResult.RouteValues
Good luck and God speed!