Following the session I had the pleasure of hosting at TechDays 2011 in Geneva, you will find here all the sources of the demonstration project as a Visual Studio 2010 and some explanation of this one. This session was made in french so all source are not translated.
The PowerPoint presentation
The PowerPoint presentation is available on SlideShare:
Les nouveautés de asp.net mvc 3
The session's video
The session's video is available on Channel 9 :
The demonstration solution
The solution is downloadable here. I am obliged to give you some explanations on these sources to understand at best. The archive contains two files: Demo and NuGet.
NuGet
The folder NuGet is a demonstration following the article published above: Create your first package NuGet. I refer you to reading this one.
Demo
Demo folder contains the Visual Studio 2010 solution used during the presentation. You can immediatly compile and run the application without modification or configuration to perform.
The application is cut along the course of the session :
- The view engine Razor
- Controllers improvements
- JavaScript & AJAX improvements
- Data validation improvements
- Dependency injection improvements
- Other news
The view engine Razor
This section of the application represents the first part of the session that was explained on the PowerPoint. You can follow through all these links the different examples. All views are on folders :
- ~/Views/Razor
- ~/Views/RazorLayout
- ~/Views/Shared
Nothing particular to note at the controller.
Controllers improvements
This section has been completely explained through demonstrations during the session. You will find the global action filters, the property ViewBag and the new types herited from ActionResult. The key points of the demonstration in the solution are in the files :
- ~/Global.asax.cs (method RegisterGlobalFilters)
- ~/Filters/SampleAttribute.cs
- ~/Controllers/ControllerImprovementsController.cs
For views of this section, you will find them under :
- ~/Views/ControllerImprovements.
JavaScript & AJAX improvements
This section was presented in PowerPoint. The views on this are below :
- ~/Views/JavaScriptImprovements
- ~/Controllers/JavaScriptImprovementsController.cs
To understand this example, it takes annalyser the source code of two examples to show that when the functionality UnobtrusiveJavaScript is disabled was a piece of JavaScript code in the page source.
Data validation improvements
This section covers examples about the interface IValidatableObject, the validation attributes and the attribute AdditionalMetadata. They have been demonstrated at the session for the first two and a PowerPoint presentation for the latter. You can find the sources involved in the sights beneath :
- ~/Views/ValidationImprovements
- ~/Controllers/ValidationImprovementsController.cs
- ~/Models/SessionModel.cs
- ~/Models/TrackModels.cs.
You can also read the article The IValidatableObject interface.
Dependency injection improvements
Again, this section was detailed during the presentation. The key points are in the solution files :
- ~/Classes/IMessageService.cs
- ~/Classes/MessageService.cs
- ~/Classes/SampleDependencyResolver.cs
- ~/Controllers/DependencyInjectionController.cs
- ~/Global.asax.cs
Other news
This section has been addressed only briefly in the session and yet behind each point, there is a demonstration.
Partial cache pages
The key files in this demonstration are :
- ~/Controllers/OtherController.cs (method GetDateTime and GetCacheDateTime)
- ~/Views/Other/CurrentDateTime.cshtml
- ~/Views/Other/Sample01.cshtml
This demonstration was to show how to implement the partial cache within views. The main view of the example (Sample01.cshtml) introduced the report of both actions (GetDateTime and GetCacheDateTime). The first date is not cached and the second is the cached date. By refreshing the view, only the first date is updated. These two measures refer to the sub view CurrentDateTime.cshtml that displays the current date and time.
At the controller (OtherController.cs), the actionGetCacheDateTime is marked with OutputCache attribute which specifies that the rendering of that must be cached. We can add parameters Duration to specify the duration of the cache in seconds and VaryByParam with the name of a parameter to specify a cache version that will be kept depending on the value of this parameter.
Sessionless controllers
The key files in this demonstration are :
- ~/Controllers/OtherSessionEnabledController.cs
- ~/Controllers/OtherSessionDisabledController.cs
- ~/Views/OtherSessionEnabled/Index.cshtml
- ~/Views/OtherSessionDisabled/Index.cshtml
The purpose of this demonstration was to present the attribute SessionState and the possibility to use it to deactivate the session on a controller. The session variable prevents the execution of several actions in parallel on a controller. This means that different requests are processed sequentially, one after the other. It's embarrassing if your view contains multiple ajax calls for example. Therefore we can disable session state and to make calls in parallel to our controller.
Both controllers OtherSessionEnabledController.cs and OtherSessionDisabledController.cs perform exactly the same instructions. OtherSessionDisabledController.cs controller is marked with the attribute SessionState which disables session state. When loading views in the browser, view ~/Views/OtherSessionDisabled/Index.cshtml generates an error when trying to access the session variable. This demonstrates that it is not only disabled but it is totally non-existent since its value is null.
You can navigate between the two examples to note that the session is not lost when you switch on a controller that session state is disabled then you return to a session whose state is active.
JSON Support
This section has been the subject of an article on my blog : JSON Binding Support. I invite you to visit it, the example being based on this demonstration.
The key files in this demonstration are :
- ~/Controllers/OtherController.cs (method SendTrack)
- ~/Views/Other/Sample03.cshtml
Helper Twitter
This demonstration was to show the ease of setting up a Twitter timeline after integration package Twitter.Helper via NuGet.
The key files in this demonstration are :
- ~/Controllers/OtherController.cs (method Sample04)
- ~/App_Code/TwitterGoodies.cshtml (added by the package Twitter.Helper)
- ~/Views/Other/Sample04.cshtml
The implementation is simple since it suffices to call the method TwitterGoodies.Profile in sight with a parameter the twitter account to view the timeline.
This Twitter helper provided by Microsoft has many method and overloads.
NuGet
As stated above, this demonstration has been the subject of an article on my blog: Create your first NuGet package. I refer you back to reading this one. The key files for this demonstration is at the root of the archive file NuGet.
References
A final point that I forgot during the session is a list of references for further MVC 3. Here is a list :