title: How to use Ajax.BeginForm MVC helper with JSON result?
body: <p>I'm trying to use the ASP.NET MVC Ajax.BeginForm helper but don't want to use the existing content insertion options when the call completes. Instead, I want to use a custom JavaScript function as the callback.</p>
  
  <p>This works, but the result I want should be returned as JSON. Unfortunately, the framework just treats the data as a string. Below is the client code. The server code simply returns a JsonResult with one field, UppercaseName.</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
      function onTestComplete(content) {
          var result = content.get_data();
          alert(result.UppercaseName);
      }
  &lt;/script&gt;
  
  &lt;% using (Ajax.BeginForm("JsonTest", new AjaxOptions() {OnComplete = "onTestComplete" })) { %&gt;
      &lt;%= Html.TextBox("name") %&gt;&lt;br /&gt;
      &lt;input type="submit" /&gt;
  &lt;%} %&gt;
  </code></pre>
  
  <p>Instead of showing the uppercase result, it is instead showing undefined. content.get_data() seems to hold the JSON, but only in string form. How do I go about converting this to an object?</p>
  
  <p>All of this seems a bit convoluted really. Is there a better way to get at the resulting content using Ajax.BeginForm? If it's this hard, I may skip Ajax.BeginForm entirely and just use the jQuery form library.</p>