Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News ASP.NET MVC 2 Brings Breaking Changes

ASP.NET MVC 2 Brings Breaking Changes

This item in japanese

A few days ago Scott Guthrie announced the production release of ASP.NET MVC 2. With it comes with many new features, but also some breaking changes. Compared to the rather strict rules around changing .NET’s base class library, the changes in ASP.NET MVC are almost caviler.

First up is IDataErrorInfo. This woefully under-documented interface has been in .NET all along, but lacks any sort of guidance on its use. In ASP.NET MVC 1 only properties that are changed will be checked for validation errors. In version 2, every property is checked during a validation cycle, which makes it quite a bit less error prone. Also, the class-wide validation will no longer occur if any of the property-level validations fail.

Html.Substitute, which is used to create uncached fragments, is no longer supported due to changes in the MVC view engine. This means anyone relying on partial caching needs to reevaluate their design.

IValueProvider replaces all uses of the much heavier IDictionary interface. According to the documentation “this change affects only applications that include custom value providers or custom model binders.”

Help methods now return MvcHtmlString instead of normal strings. This was necessary in order to support the new HTML Encoding Block syntax in ASP.NET. In both classic ASP and ASP.NET, developers were used to using <%= expression %> to mix static and dynamic content. Unfortunately it is prone to HTML-injection errors. With ASP.NET 4, developers can use the new syntax <%: expression %>. This guarantees that any string is automatically HTML encoded. If you don’t want encoding, the expression must return an IHtmlString.

Changes to the DefaultControllerFactory class require matching changes to custom controller factories, which are normally used for dependency injection.

Finally, the string “area” is now considered to be a reserved word when dealing with URL routing. This was done to support the Areas feature added in MVC 2.

Rate this Article