Skip to content

Instantly share code, notes, and snippets.

@JuanjoFuchs
Created December 17, 2012 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanjoFuchs/4319174 to your computer and use it in GitHub Desktop.
Save JuanjoFuchs/4319174 to your computer and use it in GitHub Desktop.
Very small extension to easily convert a Json ActionResult into the object it represents.
using System.Web.Mvc;
public static class WebExtensions
{
public static T ToJson<T>(this ActionResult actionResult)
{
var jsonResult = (JsonResult)actionResult;
return (T)jsonResult.Data;
}
}
@JuanjoFuchs
Copy link
Author

Usage example:

var myModel = myController.Action().ToJson<MyViewModel>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment