Breaking Changes in asp.net MVC Preview

The following changes might cause errors in existing ASP.NET MVC 1.0 applications.

Installing ASP.NET MVC 2 Preview 2 Alongside ASP.NET MVC 1.1

The runtime component of ASP.NET MVC is shared by Visual Studio 2008 and Visual Studio 2010. If you have ASP.NET MVC 1.1 installed, you must uninstall it before you install ASP.NET MVC 2 Preview 2. Use the following steps to uninstall ASP.NET MVC 1.1 and install ASP.NET MVC 2:

1. From the Windows Control Panel, open Add/Remove Programs.

2. Uninstall Microsoft Visual Studio 2010 Tools for ASP.NET MVC 1.1

3. Uninstall Microsoft ASP.NET MVC 1.1

4. Install ASP.NET MVC 2

NGen Priority Change

When System.Web.Mvc.dll is installed in the Global Assembly Cache (GAC), the installer also invokes the NGen service to generate a native image. In previous versions of the installer, the service was invoked with a service request priority of 0, which caused the installer to create a native image immediately as part of the setup process. Many customers have reported problems where the NGen service fails, forcing the installation of MVC to be rolled back. These failures can usually be attributed to missing assemblies or corrupt entries inside the registry hive that is maintained by the CLR. However, the cost for customers is that they cannot install MVC until these issues have been addressed.

Starting with MVC 2 Preview 2, all the assemblies for which native images are created are queued by lowering the priority of the service request to 3. This will allow the installation of MVC to complete even if other problems arise, because native images for System.Web.Mvc.dll will be created only when the system is idle after the installation process.

Posted in: problems and solutions asp.net | Tags: asp.net asp.net mvc mvc 2.0 asp.net mvc framework system.web.mvc mvc 2 preview 2 priority ngen alongside

New HiddenInputAttribute for Templated Helpers in asp.net mvc 2 preview 2

When the new HiddenInputAttribute class is applied to a property, the attribute indicates to the editor template whether a hidden input element should be rendered when editing the model. (The attribute sets an implicit UIHint value of HiddenInput). The DisplayValue property allows you to control whether the value is displayed in editor and display modes. When the attribute is set to false, nothing is displayed (not even the HTML markup that normally surrounds a field).

You might use this attribute in the following scenarios:

· When a view lets users edit the ID of an object and it is necessary to display the value as well as to provide a hidden input element that contains the old ID so that it can be passed back to the controller.

· When a view lets users edit a binary property that should never be displayed, such as a timestamp property. In that case, the value and surrounding HTML markup (such as the label and value) are not displayed.

The following example shows how to use the HiddenInputAttribute class.

public class ProductViewModel {

[HiddenInput] // equivalent to [HiddenInput(DisplayValue=true)]

public int Id { get; set; }

public string Name { get; set; }

[HiddenInput(DisplayValue=false)]

public byte[] TimeStamp { get; set; }

}

When the attribute is set to true (or no parameter is specified), the following occurs:

· In display templates, a label is rendered and the value is displayed to the user.

· In editor templates, a label is rendered and the value is rendered in a hidden input element.

When the attribute is set to false, the following occurs:

· In display templates, nothing is rendered for that field.

· In editor templates, no label is rendered and the value is rendered in a hidden input element.

Posted in: asp.net | Tags: asp.net asp.net mvc mvc 2.0 mvc 2 preview 2 productviewmodel hiddeninput displayvalue

additional changes to existing types and members for ASP.NET MVC 2 Preview 2

The following additional changes have been made to existing types and members for ASP.NET MVC 2 Preview 2.

· Removed the IsNullableValueType property from the TemplateInfo class and added it to ModelMetadata. When ASP.NET MVC looks up a template for Nullable<T>, the type of T is used for the type-based template lookup. This new property lets the template author know that the original value was a nullable type.

· Changed the Controller.Execute method to throw an exception when it is called more than once on the same instance. Controllers are meant to serve a single request and to be executed only once. Many developers were running into subtle bugs when they accidentally set an Inversion of Control (IoC) container to return a singleton instance of a controller rather than a new instance per request. This change makes the contract for controllers explicit.

· Changed templated helpers to return their output as a string rather than writing the output directly to the response. Before this change, the helpers returned an empty string and wrote their output directly to the response.

· Changed the Controller class so that it no longer inherits from MarshalByRefObject.

· Added support for the DataType.Password enumeration value for the DataTypeAttribute class. When a property is marked with this attribute, the default editor template will render a password input element.

· Made the AuthorizationContext(ControllerContext context) constructor obsolete. Instead, use the constructor that accepts both a ControllerContext parameter and an ActionDescriptor parameter.

· Made performance improvements to expression-based helper methods such as the template helpers. Helpers now cache compiled LINQ expressions.

· Added TemplateInfo.GetFullHtmlID and Html.GenerateIDFromName methods that are used to generate the recommended HTML id attribute value for an element within a template. This helps template authors make sure their templates work when they are nested in other templates.

· Added new attributes for simple REST scenarios, including HttpPutAttribute, HttpDeleteAttribute, and HttpGetAttribute. For more information, see Overriding the HTTP Method Override Verb earlier in this document.

· Changed the default editor template for nullable Boolean values to render a drop-down list that has three options: “Not Set”, “True”, and “False”. When “Not Set” is selected, the value that is submitted to the server is an empty string.

· Changed model types so that they can be either value types or reference types. This allows view pages and other types to support built-in .NET Framework value types such as System.DateTime and System.Int32.

· Changed the framework so that if a controller namespace is specified as part of a route registration (for example, by using the namespaces parameter in a call to the MapRoute method), the framework now looks in that namespace and its children for potential controller matches. For example, if the namespace MyNamespace is specified, the framework will look in the equivalent of MyNamespace.* for a matching controller.

· Renamed the htmlFieldPrefixId parameter for the template helper methods to htmlFieldPrefixName, and renamed TemplateInfo.GetFullHtmlFieldId renamed to TemplatInfo.GetFullHtmlFieldName. The new names better represent the purpose of the parameter and property.

Posted in: programming asp.net | Tags: asp.net asp.net mvc mvc 2 preview 2 httpgetattribute httpdeleteattribute marshalbyrefobject templateinfo getfullhtmlid generateidfromname nullable htmlfieldprefixid getfullhtmlfieldname