views:

366

answers:

3

Can I run a MVC 1 application using the MVC 2 assemblies without a hitch? I understand that some 3rd party tools have had stuff broken in MVC 2, but let's assume I'm not using those any other tools.

+7  A: 

There have been breaking changes.

If you want a 1.0 project to run on 2.0, it does look for things in different places; so you'd have to migrate the application to 2.0..

Here are the changes that could possibly 'break' (current as of Preview 2):

Changes in Preview 2

Helpers now return an MvcHtmlString object

In order to take advantage of the new HTML-encoding expression syntax in ASP.NET 4, the return type of the HTML helpers is now MvcHtmlString instead of a string. Note that if you use ASP.NET MVC 2 and the new helpers with ASP.NET 3.5, you will not be able to take advantage of the HTML-encoding syntax; the new syntax is available only when you run ASP.NET MVC 2 on ASP.NET 4.

JsonResult now responds only to HTTP POST requests

In order to mitigate JSON hijacking attacks that have the potential for information disclosure, by default, the JsonResult class now responds only to HTTP POST requests. AJAX GET calls to action methods that return a JsonResult object should be changed to use POST instead. If necessary, you can override this behavior by setting the new JsonRequestBehavior property of JsonResult. For more information about the potential exploit, see the blog post JSON Hijacking on Phil Haack’s blog.

Model and ModelType property setters on ModelBindingContext are obsolete

A new settable ModelMetadata property has been added to the ModelBindingContext class. The new property encapsulates both the Model and the ModelType properties. Although the Model and ModelType properties are obsolete, for backward compatibility the property getters still work; they delegate to the ModelMetadata property to retrieve the value.

Changes in Preview 1

DefaultControllerFactory class changes break custom controller factories that derive from it

This change affects custom controller factories that derive from DefaultControllerFactory . The DefaultControllerFactory class was fixed by removing the RequestContext property and instead passing the request context instance to the protected virtual methods GetControllerInstance and GetControllerType.

Custom controller factories are often used to provide dependency injection for ASP.NET MVC applications.

To update the custom controller factories to support ASP.NET MVC 2, change the method signature or signatures to match the new signatures, and use the request context parameter instead of the property.

“Area” is a now a reserved route-value key

The string “area” in Route values now has special meaning in ASP.NET MVC, in the same way that “controller” and “action” do. One implication is that if HTML helpers are supplied with a route-value dictionary containing “area”, the helpers will no longer append “area” in the query string.

If you are using the Areas feature, make sure to not use {area} as part of your route URL.

Known Issues

The Add View dialog box throws a NullReferenceException when the Create strongly-typed view check box is checked, a View Content selection other than “Empty” is selected, and a View data class type name is specified for a type that does exist. When specifying a type name, either use the drop-down list to select the type name or type the fully-qualified type name. For types that do not exist, you must set View Content to “Empty”.

George Stocker
Another breaking change is that the ValueProvider was changed from a Dictionary to the IValueProvider interface. It doesn't break anything unless you use Custom ModelBinders. It also gives you the ability to create your own ValueProviders if you are getting data from places other than the traditional form/querystring/etc...
Keith Rousseau
You are correct that you will need to migrate the project. There are pretty detailed instructions in the Readme that comes with mvc2.
Keith Rousseau
I had originally answered that you could run 1.0 on 2.0 assemblies, and that 'I thought'; but since I've actually migrated an existing ASP.NET MVC 1.0 project to 2.0, there's no need for the 'I Think' (which was in reference to the idea that you wouldn't have to change anything to run a 1.0 on 2.0 -- even though you would.)
George Stocker
Just found the breaking change of setters in modelbinding context. I don't understand why microsoft throws runtime exceptions to notify developers of breaking changes when the compiler could be used.
Paco
+1  A: 

Check out this document. You'll learn about the breaking changes : http://go.microsoft.com/fwlink/?LinkID=157072

Thomas Jaskula
+1  A: 

One gotcha that has bitten me is that all the fields of a model are now always validated on a post.

The changes is described by Brad Wilson here.

Steve Anderson's blog post describes the issue and my favorite solution (using a custom validator).

jslatts