title: Ajax BeginForm - OnFailure return error message
body: <p>I am using Ajax.BeginForm to call my application to run some code. On error, I would like to return the custom error message which I will create.</p>
  
  <p>However I haven't been able to do it this far. This is what I have:</p>
  
  <p>Controller:</p>
  
  <pre><code>        [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;JsonResult&gt; Edit(UserViewModel model) {
              Response.StatusCode = 500;
              return Json(new { error = "Broken" });
          }
  </code></pre>
  
  <p>Ajax.BeginForm:</p>
  
  <pre><code>@using (Ajax.BeginForm("Edit", "User", new AjaxOptions { HttpMethod = "POST", OnSuccess = "window.location.reload();", OnFailure = "AjaxFailed(error);" }, new { @class = "form-horizontal", role = "form", @id = "EditForm" })) {
  }
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function AjaxFailed(error) {
      debugger
      $(".ErrorBox").prop('hidden', false);
      $('.ModalErrorText').text("An error occured, please review the data and try again.");
  }
  </code></pre>
  
  <p>I would've thought that the BeginForm would have caught the error which I returned and passed it through to the Javascript, but it doesn't. Can anyone help me return the error message to me Javascript?</p>
  
  <p>Thanks</p>