First thoughts on ASP.NET MVC Preview 3
I had a chance to play with the latest ASP.NET MVC drop tonight. There’s a few changes (some of which came in Preview 2) but a few items caught my eye fairly quickly.
ActionResult
This change came with Preview 2, but it’s worth mentioning. Instead of controller actions returning void, they now return an ActionResult instance. This increases testability and separates functionality. Testability because now controllers can be tested without mocking out all the requirements for invoking the view, and functionality because the loading and invoking of an action’s view is encapsulated in a class structure apart from the controllers.
JsonResult
Something that is included new in Preview 3 is JsonResult (a subclass of ActionResult). It looks like some of my crazy ideas weren’t so crazy after all? A new method on the controller, "Json()", takes a serializable object and returns a JsonResult which uses the obsoleted (whoops??) JavaScriptSerializer to render the object as JSON.
So a controller’s action could look like this:

RedirectToRoute
If a controller action needed to redirect, our only option (until now) has been RedirectToAction which accepts an action name and optional controller name. That’s not bad, but now we have RedirectToRoute which allows us to redirect to a named route, making things more flexible and easier to change (without mass find/replacing all over the place).
And more…
Scott Guthrie has more details, and Scott Hanselman (so many Scotts!) has a few updated screencasts. Be sure to check them out.
Things with MVC are solidifying and starting to look pretty good. Check out the MvcContrib or CodeCampServer projects for some decent reference implementations.
May 28th, 2008 at 12:35 am
The JavaScriptSerializer class is actually undeprecated in .NET 3.5 SP1.
Thanks,
Scott
May 28th, 2008 at 1:29 am
Looks like I wasn’t the only one who thought depreciating JavaScriptSerializer was a funny thing to do.
May 28th, 2008 at 8:07 am
@scottgu,
Excellent, thanks for the heads up! (Looks like it’s time for me to set up a VM and install the beta.
)
May 28th, 2008 at 9:32 am
[...] to Scott Guthrie (see comments in this post) it appears that the JavaScriptSerializer will be undeprecated in .NET 3.5 SP1. In was [...]
May 28th, 2008 at 11:00 am
[...] First Thoughts on ASP.NET MVC Preview 3 (Aaron Lerch) [...]
May 28th, 2008 at 2:31 pm
With return Json(item), how do you specify which View you want to be rendered to accept the Json?
May 28th, 2008 at 3:34 pm
@EricTN,
Calling Json(item) will serialize the object into JSON and return it as content-type “application/json” (if I remember right). It won’t call a view, the serialized representation is the view.
May 28th, 2008 at 7:45 pm
Hi Aaron, Scott Gu says that the json return would be a method that would enable MVC to work with an RIA client like Silverlight (among many other things I’m sure). Would you be able to update your MvcServiceLibrary solution to use the new json feature of Preview 3?
June 2nd, 2008 at 4:31 pm
[...] First thoughts on ASP.NET MVC Preview 3 [...]
June 2nd, 2008 at 4:32 pm
[...] First thoughts on ASP.NET MVC Preview 3 [...]
June 27th, 2008 at 11:15 am
Thank you for undeprecating JavaScriptSerializer!! The dynamic nature makes it a pleasure to use..