title: How can I return error message to Ajax call
body: <p>I have a new Mvc Core application. I use jquery to make an ajax call to my controller. I am trying to return an error message in case of an exception in the controller. Here is my code sample:</p>
  
  <pre><code>    public async Task&lt;IActionResult&gt; UpdateAllocations([FromBody]AllocationsDto allocationsDto)
      {
   ...
              catch (Exception ex)
              {
                  Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
  
                  return Json(new { success = false, responseText = ex.Message });
  
              }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>  $.ajax({
          type: "POST",
          url: "/Allocation/UpdateAllocations",
          data: JSON.stringify(allocationData),
          contentType: "application/json; charset=utf-8",
          dataType: "json"
      })
          .done(function (data) {
  
          })
          .fail(function (xhr, status, error) {
              displayError("The ajax call to UpdateAllocations() action method failed:",
                  error, "Please see the system administrator.");
          });
  </code></pre>
  
  <p>But the error parameter is empty, and status has only one word "error" as well as  xhr.statusText. How can I return my own custom text, in this case ex.Message??</p>