Created
December 25, 2014 14:56
-
-
Save EmeraldCoder/9a35c66820fec33837d1 to your computer and use it in GitHub Desktop.
C# MVC JSON Helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using System.Web.Script.Serialization; | |
namespace Web.Helpers | |
{ | |
public static class ExtensionMethods | |
{ | |
public static MvcHtmlString ToJson(this HtmlHelper html, object obj) | |
{ | |
JavaScriptSerializer serializer = new JavaScriptSerializer(); | |
return MvcHtmlString.Create(serializer.Serialize(obj)); | |
} | |
public static MvcHtmlString ToJson(this HtmlHelper html, object obj, int recursionDepth) | |
{ | |
JavaScriptSerializer serializer = new JavaScriptSerializer(); | |
serializer.RecursionLimit = recursionDepth; | |
return MvcHtmlString.Create(serializer.Serialize(obj)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment