Controller.Json Method (System.Web.Mvc)

Switch View :
ScriptFree
.NET Framework Class Library
Controller.Json Method

Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Overload List

  Name Description
Protected method Json(Object) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON).
Protected method Json(Object, String) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.
Protected method Json(Object, JsonRequestBehavior) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified JSON request behavior.
Protected method Json(Object, String, Encoding) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format.
Protected method Json(Object, String, JsonRequestBehavior) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the specified content type and JSON request behavior.
Protected method Json(Object, String, Encoding, JsonRequestBehavior) Creates a JsonResult object that serializes the specified object to JavaScript Object Notation (JSON) format using the content type, content encoding, and the JSON request behavior.
Top
See Also

Reference

Community Content

LukePuplett
Important: AllowGet and JSON hijacking
Before using this method, please read up on the security implications http://haacked.com/archive/2009/06/25/json-hijacking.aspx

Balaje Sankar
Content Type
The content type in Json method needs to be set to "application/json" so that the json objects value can be accessed in Javascript using . notation.
eg
Json(new { Text1= somevalue1, Text2= somevalue2 }, @"application/json");
- Balaje Sankar (http://dotnetech.wordpress.com)