
The other day MVC 2 Preview 1 became available to the general public. This release of the framework contains very significant innovations, which I will try to briefly describe in this article. First of all, it should be noted that, as in the case of the first version, the status of “Preview 1” means a technical demonstration of changes and new functionality. It is expected that the interested developer community will test and evaluate this release and based on feedback in the MVC Framework, changes will be made for the release of Preview 2 and so on, before the final release of the second version. In other words, this release is not intended for use, as they say, “in production”. It is very likely that subsequent releases may contain more or less significant changes, due to which the compatibility of the draft written for preview 1 with preview 2 releases and so on may be broken.
What's new?
So, what's new in this release? I bring to your attention a more or less complete list of changes and innovations in the MVC Framework 2 compared with the first version:
- Strongly Typed Helpers (Strongly Typed UI Helpers) - allow you to define in the markup the presentation of certain data through the type obtained from the lambda expression. This allows, firstly, using intellisense, and, secondly, reducing the number of possible errors at the compilation stage;
- Templated Helpers — allow you to map a piece of markup to a specific complex type and then render the markup to display information, such as markup to edit this information, with a single line of code. Used in conjunction with the mechanism of strongly typed helpers;
- Areas (Areas) - the mechanism of areas in a complex and large project allows to distinguish (or vice versa merge from small projects into one) different in nature functional. For example, in one project you can define areas for a forum, a blog, a news site, a gallery of pictures, and other parts. In other words, areas are add-ons for controllers, which allows them to be grouped;
- Support for data notes (Data Annotations). MVC Framework 2 received support for the .net component model mechanism, which is implemented in the System.ComponentModel.DataAnnotations namespace. This allows you to create a definition of meta-information for types and properties, which is then used in different places, for example, to validate data received from the client on the server side;
- The new attribute [HttpPost] allows you to specify the same thing as [AcceptVerbs (HttpVerbs.Post)], only make it shorter;
- Component model support also extends to support for the DefaultValue attribute, which allows you to specify a default value for action parameters. In C # 4.0, the default parameter mechanism built into the language can be used instead;
- Binding to binary data allows you to transparently match binary data represented by base64 strings with action parameters of type byte [].
What changed?
In addition to the innovations in the MVC Framework 2, some of the old features have also changed:
- The new protected CreateActionInvoker method of the Controller class, which is called by the ActionInvoker property for the lazy creation of ActionInvoker, if it has not yet been created;
- A new protected virtual method OnAuthorizationFailed in the AuthorizationFilter class, which allows filters inherited from AuthorizationFilter to handle the event when authorization was not performed;
- new Add method (string key, object value) for the ValueProviderDictionary class, which allows using the simplified dictionary initialization syntax for ValueProviderDictionary;
- new get_object method for class Sys.Mvc.AjaxContext . This javascript method is similar to the old get_data method, but differs from it in that it returns a JSON object if it was returned by the client;
- A new ActionDescriptor property in the AuthorizationContext class that contains information about the action;
- RequestContext property removed in DefaultControllerFactory . Instead , RequestContext is passed to the GetControllerInstance and GetControllerType methods . This change may “break” previous user implementations of the controller factories;
- the area value is now reserved for use in route pattern parameters.
What is fixed?
In addition to innovations and changes, some bugs and bugs were fixed. Their translation was somewhat difficult, since I did not encounter any of the bugs. Therefore, if you find an error in the translation, let me know:
- fixed a bug when compiling view, which contained Unicode characters in the title;
- HTML helpers caused a NullReferenceException exception when adding a ModelError without setting a value. Now the exception is not called;
- Previously, the SessionStateTempDataProvider class stopped working with an error if the session state mechanism was not enabled. Now the provider throws an exception only if an attempt is made to save data to the session state object when this object is disabled;
- AJAX helpers can now submit submit buttons or submit images as part of a request when sending data from a form. In order for this to work in old projects, after updating the project itself, update the MicrosoftMvcAjax.js library;
- Earlier, an error occurred when compiling views with the view type ViewMasterPage <T>, which did not contain a single block <% = ...%>. This has been fixed.
What will happen next?
The official
MVC Roadmap page lists the following areas in which the MVC Framework will evolve:
- client side validation;
- strongly typed helpers for creating form fields;
- strongly typed helpers for creating hyperlinks;
- asynchronous actions;
- expansion of the functional areas.
In addition, if you collect the answers to ScottaG in the comments, you can make a small list of what the development team is working on:
- strongly typed action generators (strongly typed action generators);
- caching the results of lambda expressions to optimize the performance of views and UI helpers;
- RenderAction will be included in the MVC Framework closer to the release;
- MVC Framework V2 will not appear for Visual Studio 2010 beta1, but will be enabled by default in beta2;
- And finally, to the question about classic asp.net and whether there will be something new for it, Scott replied: “Absolutely! WebForms coming with ASP.NET 4.0. Non-MVC features. ”. Zhdems.
useful links
I think the links for the first time is enough. I will try, if possible, to write several articles on the topic.
Conclusion
MVC Framework is developing rapidly. The new functionality that appeared in V2 Preview 1 is very interesting and sure will be widely used in practice. Do not forget only that, as before, preview versions are not recommended for use in production. If you still risk using some of the new features in a running application, then be prepared that subsequent releases of MVC V2 may require rewriting some of the code.
While the developers are waiting for us with you feedback and reports on errors found. Enjoy all the programming!
