ASP.NET MVC Preview 3 Release

I’ll write up more as I explore…

Update: so far… excellent work.  The different return results from Actions are very powerful  – JsonResult, ActionResult, ContentResult

Take the JsonResult.  Previously I created a ‘ToJson’ extension method with a response.write on a void action call.

With preview 3, I return a JsonResult instead, and use the ‘Json’ function that does the same thing my extension method was doing and then returns the JsonResult.  For example:

        public JsonResult SetClaimReadyToPrint(string id) //claimid
            try {
                Claim claim = ClaimsDao.GetById(new Guid(id), true);
                if (claim.ClaimStatus == ClaimStatus.P)
                    return Json(new JsonData(true, "Claim has already been paid");
                claim.ClaimStatus = ClaimStatus.R;

                return Json(new JsonData("Set to Ready to Print"));
            catch (Exception ex) {
                return Json(new JsonData(true, "Error setting to ready status " + ex.Message));

I am using my ‘JsonData’ class- a serializable object to store the results

With just content, I use the ContentResult – this replaces any ugly ‘response.write’ calls.

The best part of all (outside of readability and no response write!) is that it’s easy to test!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s