Wednesday, March 2, 2011

my MVC 3 journey

Went to Seattle last week to attend a very cool workshop. Exposed to many new terms, technologies and tools used in a demo project. Summarize some of them as below:

1) Razor (cshtml) - Wondering why we no longer saw any aspx files in that project, but only cshtml files. Well, welcome to the new Razor world. Did more reading about Razor afterwards. It looks very neat and compact. Here is one of the best blogs about Razor for beginners - Introducing "Razor" – a new view engine for ASP.NET from Scott Gu.

2) EF Code First - the coolest thing about this is that - you don't need to create database or tables beforehand. When you run your application first time, if it cannot find the database and the tables, it will create them based on your classe model definitions. Like a magic! Of course, you would need to wire the db connection in the web.config file. Further more, if you make changes to any classes (add / remove properties), you can also wire the application to allow drop and recreate the database in the Application_Start() event using "DbDatabase.SetInitializer". For sure, this only makes sense in the testing / development environment, where losing data is not an issue. One more tip, you can override default data types by using System.Data.Entity.ModelConfiguration, and method OnModelCreating().

3) Validation - The validations in MVC 3 look much simplier and less code comparing to what we are using right now. Microsoft takes care of both the client-side and server-side (in case the JavaScript is disabled in user's browser) validations for you. All you need to do is to add the decorations above your class properties like this - [Required(ErrorMessage = "This field XXXXX is required")]. Availabel built-in validations include "Required", "StringLength", "Range"... Cool!

4) QUnit - how can you do unit test if all the logics are moved into JavaScript. Qunit or Jasmine are used in the demo. Having tools like these is an absolute step-up in the JavaScript world.

Finally, here is the link to talk about all the related technlogies included in this project Announcing release of ASP.NET MVC 3, IIS Express, SQL CE 4, Web Farm Framework, Orchard, WebMatrix , again from Scott Gu.

This is one of the best workshops. Feeling smarter now. ;)