问题
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.
回答1:
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”.
回答2:
Check out this document. You'll learn about the breaking changes : http://go.microsoft.com/fwlink/?LinkID=157072
回答3:
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).
来源:https://stackoverflow.com/questions/2202455/is-asp-net-mvc-1-forwards-compatible-with-asp-net-mvc-2