Monday, October 20, 2008

Update to JSON Service Provider using ASP.NET MVC Beta as well as testing Dates with Microsoft AJAX Client Templating

Recently Microsoft has updated the ASP.NET MVC to Beta status, and along with that came code changes. One of the code changes to the IModelBinder and how it interacts with the Parameter bindings broke what I wrote on the last post (utilizing ASP.NET MVC as a JSON Service Provider, and coding the entire web site on the client side).

Upon loading the Beta bits, I realized my AJAX Parameter function was infinite looping. The reason is that the Model Binder defaults to trying to bind Complex Types in the Action Parameter to the form values being passed back, however, since I am not doing a form postback, it could not bind that to the complex type, and could not run the ActionExecuting on the AjaxParameterAttribute I had set.

So to fix this, I thought I would use the IModelBinder and re-do that section of my code using the new bits. Here is the result:

As you can see, I updated the example to be more real world with caching out the original server side object to do compares against the modified version:


I also added 2 new Javascript helpers to test Dates with the Client Side AJAX Templating engine:

And the HTML Code to test Live Binding Dates with the MVC Beta:
image image 

Before I change the Live Binding Date using the Microsoft AJAX Client Template:

After I merely type a different date, no post back, it auto converted the string back to the Javascript Date property on my Model Object (notice how the convert and convertBack Live Templates handle the display and changing the javascript object – I have complete control over it):


After post back, testing the IModelBinder to serialize the Javascript Object in JSON to a C# object:


This is just cool. Anyway you slice this, ASP.NET MVC with Microsoft AJAX Client Templating engine is just simple, effective, and elegant. I am falling in love with these frameworks the more and more I play with them.

Also, in my opinion, using the IModelBinder is a cleaner approach to the original solution I used earlier. It just feels more separated out.

Updated Source Code

Questions, comments, opinions?

kick it on

No comments: