This post is part of the series I’m doing on the newly released ASP.NET MVC 3.
The official tagline is that ASP.NET MVC 3 enables richer JavaScript scenarios and takes advantage of emerging HTML5 capabilities. Sounds good, but what improvements have actually been made? Let’s take a look.
How is it used
I have always felt the MVC Ajax helpers were lacking – I pretty much always write the Ajax calls by hand using jQuery. Let’s take a look at an example using Ajax.
On the server I have created the following action.
My partial view simply displays a success message.
This works in both MVC 2 and MVC 3. So what’s the big deal?
How to do this in MVC 2
The difference is in the generated JavaScript and includes. In MVC 2 we need the following includes.
Let’s take a look at the generated JavaScript.
This works, but it’s rather messy. For one thing, we need to use the Microsoft Ajax libraries instead of the common jQuery ones, and the generated code does not follow the principle of Unobtrusive JavaScript.
Now let’s take a look at the same scenario in MVC 3. We still need an include, but it’s the jQuery version.
Now the same code generates very nice markup.
Which is much neater. What about ActionLinks? (I’m using Razor as the View Engine)
This generates the following markup.
Very cool.
Further Reading
Again, MVC 3 has only recently been released so there is very little information available. The only similar post I found was by Jeremy Skinner.