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.

This entry was posted on Tuesday, May 27th, 2008 at 10:57 pm and is filed under asp.net mvc. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

11 Responses to “First thoughts on ASP.NET MVC Preview 3”

  1. scottgu Says:

    The JavaScriptSerializer class is actually undeprecated in .NET 3.5 SP1. :-)

    Thanks,

    Scott

  2. Craig Says:

    Looks like I wasn’t the only one who thought depreciating JavaScriptSerializer was a funny thing to do.

  3. aaron Says:

    @scottgu,

    Excellent, thanks for the heads up! (Looks like it’s time for me to set up a VM and install the beta. :) )

  4. Dan Rigsby » JavaScriptSerializer Undeprecated in .NET 3.5 SP1 Says:

    [...] to Scott Guthrie (see comments in this post) it appears that the JavaScriptSerializer will be undeprecated in .NET 3.5 SP1.  In was [...]

  5. Dew Drop - May 28, 2008 | Alvin Ashcraft's Morning Dew Says:

    [...] First Thoughts on ASP.NET MVC Preview 3 (Aaron Lerch) [...]

  6. EricTN Says:

    With return Json(item), how do you specify which View you want to be rendered to accept the Json?

  7. aaron Says:

    @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.

  8. EricTN Says:

    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?

  9. Wöchentliche Rundablage: ASP.NET MVC, .NET, ADO.NET Data Services, Silverlight, WPF… | Code-Inside Blog Says:

    [...] First thoughts on ASP.NET MVC Preview 3 [...]

  10. Weekly Links: ASP.NET MVC, .NET, ADO.NET Data Services, Silverlight, WPF… | Code-Inside Blog International Says:

    [...] First thoughts on ASP.NET MVC Preview 3 [...]

  11. me Says:

    Thank you for undeprecating JavaScriptSerializer!! The dynamic nature makes it a pleasure to use..