title: How can I return a JSON result to a Ajax.BeginForm
body: <p>I have got this simple form:</p>
  
  <pre><code>@using (Ajax.BeginForm("CreateProductFromAjaxForm","Product" , 
                    null, 
                    new AjaxOptions() {  HttpMethod = "post", OnSuccess = "getresult" },
                    null))
  {
      @Html.EditorFor(m =&gt; m)
      &lt;hr /&gt;
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" class="btn btn-info" value="Next" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }  
  </code></pre>
  
  <p>And, for testing, a simple controller:</p>
  
  <pre><code>    [HttpPost]
      public JsonResult CreateProductFromAjaxForm(CreateProductModel model)
      {
          if (!ModelState.IsValid)
          {
              return new JsonResult()
              {
                  JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                  Data = new { result = "error" }
              };
          }
  
         //add to database
  
          return new JsonResult()
          {
              JsonRequestBehavior = JsonRequestBehavior.AllowGet,
              Data = new { result = "success"}
          };
      }  
  </code></pre>
  
  <p>I have added these to the Web.Config:</p>
  
  <pre><code> &lt;add key="ClientValidationEnabled" value="true" /&gt;
   &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
  </code></pre>
  
  <p>and these to my script bundle:</p>
  
  <pre><code>bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                      "~/Scripts/jquery-{version}.js",
                      "~/Scripts/jquery.validate.js",
                      "~/Scripts/jquery.validate.unobtrusive.js"
                      ));
  </code></pre>
  
  <p>After clicking the "Submit" button, the resulting page just shows:</p>
  
  <pre><code>{"result":"success"}
  </code></pre>
  
  <p>I would expect that I could handle the result in the <code>OnSuccess="getresult"</code> handler, but it doesn't seem to work.</p>
  
  <p>Basically I am using the <code>Ajax.BeginForm</code> mainly for the clientside validation. </p>
  
  <p>Can you tell me whats wrong?</p>
  
  <p>UPDATE: I added the  <code>HttpMethod = "post"</code> to the AjaxOptions. </p>
  
  <p>UPDATE: The <code>getresult</code>, is defined above the <code>Ajax.BeginForm</code> like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var getresult = function (data) {
          alert(data.result);
      };
  &lt;/script&gt; 
  </code></pre>