Things I learned about ASP.NET MVC 2 at the jQuery Conference
I’m at the jQuery Conference in Cambridge, MA this weekend. Today was day one of two and it was a great start to the conference. Stephen Walther from the ASP.NET team at Microsoft gave a talk on building apps with ASP.NET and jQuery. The talk got very interesting when he mentioned that he was running unreleased bits from a recent internal build. There were two things that were previously unannounced that I found interesting.
The first thing Stephen demo’d was using the jQuery Validation plugin with MVC. It’s been publicized that Microsoft is planning to ship the Validation plug-in similar to how jQuery core is included. What hasn’t been shown publically (to my knowledge) were any code examples. The one that caught my eye the most was this snippet which was placed just under the opening <body> tag in the view (from memory, exact syntax may vary):
<% Html.EnableClientValidation(); %>
After the talk Stephen let me view source on the outputted page. This helper method outputs the JSON structures needed for the validation plugin to work. Interestingly, it outputs them at the end of the page just before the closing body tag. Does this remind you of anything? Reminds me of Webforms. Declare something one place in your code and have it do things somewhere else. The other thing I don’t like about this syntax is the name of the method. I don’t think that’s a very descriptive term for what it’s actually doing. I’m working on limited information here though so it might be doing more than just outputting the JSON data. It’s still only pre-Preview 2 and MVC 1 went through 5 previews and a couple RCs with lots of refinements along the way so it could very well change.
The second interesting thing that was discussed was a change in the way GET requests for JSON are going to be handled. The reasons for this have been covered extensively. If you want to allow JSON to be returned via a GET request, you’re going to have to be more explicit about it before you risk shooting yourself in the foot. While the sentiment behind the decision is good, I’m not a fan of the current way you have to specify it (again, from memory):
public ActionResult GetJson() {
return new JsonResult(data, JavascriptBehavior.AllowGet);
}
What I deduce from this is that by default JsonResult won’t return data if the request is a GET without explicitly allowing it. This change would break existing code since it would need to be updated to allow the GETs. If the default is going to be changed though, why add the parameter? Why not just check to make sure the proper AcceptVerbs attribute values are present? Again it’s early and could change even before the next preview, but it’s a curious change.
From my experience it’s rare when MS demos something at a conference that wasn’t already covered in some other form (usually blog posts) so it was an exciting afternoon to get a little advance preview of the changes coming in MVC 2. Even though these two features aren’t implemented the way I would like, the MVC team has proven that they’re listening to feedback and willing to make changes along the way if better ideas are presented. That sort of openness into the process is reassuring and I’m appreciative of the team’s efforts.
Tomorrow there will be an open spaces meeting for ASP.NET folks that use jQuery. I’m looking forward to sharing some ideas and helping some others out if they have any questions that I can answer. If anything interesting comes out of it, I’ll be sure to pass it on. Also, be sure to follow me on Twitter if you’re interested in my thoughts as the conference goes on tomorrow.




