title: MVC controller encoding JSON with Json(object) vs JavaScriptSerializer().Serialize(object)
body: <p>In my current MVC application I perform an AJAX call to the controller. The controller gets an object from the database and returns it in the form of a JSON response. My confusion is between using the <a href="https://msdn.microsoft.com/en-us/library/system.web.mvc.controller.json(v=vs.118).aspx" rel="nofollow">Controller.Json</a> method vs <a href="https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-US&amp;k=k(System.Web.Script.Serialization.JavaScriptSerializer.Serialize)" rel="nofollow">JavaScriptSerializer.Serialize</a>(object). My object I am converting is a simple class called <code>PhoneSerializable</code> with a few public properties of type <code>string</code> and <code>int</code>. </p>
  
  <p>I have the following:</p>
  
  <pre><code>var serializedPhone = jsSerializer.Serialize(new PhoneSerializable(phone));
  return new ContentResult {Content = serializedPhone, ContentType = "application/json"};
  </code></pre>
  
  <p>This works correctly and I get a JSON response that my AJAX caller can parse.
  Yet some online examples I have seen use this instead:</p>
  
  <pre><code>return Json(new PhoneSerializable(phone));
  </code></pre>
  
  <p>The response of this has mostly <code>null</code> properties and a <code>DenyGet</code> header which means it failed parsing or something. The documentation for the <code>Json(object)</code> method states that it uses the same javascript serializer for the object yet it fails to convert my simple object to JSON. </p>
  
  <p>What am I missing? I would like to use <code>Json(object)</code> since it is much cleaner but I cannot seem to get it to work. </p>
  
  <p>EDIT WITH ANSWER:</p>
  
  <p>The <code>Json()</code> method was defaulting to "DenyGet" adding more parameters fixed the issue and it now works:</p>
  
  <pre><code>return Json(new PhoneSerializable(phone), 
              "application/json", 
              JsonRequestBehavior.AllowGet);
  </code></pre>