title: .Net Core API return error msg to Ajax
body: <p>Test.cshtml:</p>
  
  <pre><code>function insertButton(item) {
          var options = {};
          options.url = "/api/test";
          options.type = "POST";
          var obj = datas;
          obj.name = $("#insertName").val();
          obj.url = $("#insertUrl").val();
          console.dir(obj);
          options.data = JSON.stringify(obj);
          options.contentType = "application/json";
          options.dataType = "html";
  
          options.success = function (msg) {
              swal({ type: "success", title: msg, showConfirmButton: !1, timer: 2000 })
              getAll();
          },
          options.error = function (msg) {
              swal({ title: "ERROR", text: msg, icon: "error", type: "error", confirmButtonText: "OK" })
          };
  
          $.ajax(options);
      }
  </code></pre>
  
  <p>TestController.cs</p>
  
  <pre><code>    [HttpPost]
      [Route("api/test")]
      public async Task&lt;IActionResult&gt; InsertData([FromBody]Sites sites)
      {
          _context.Add(sites);
          await _context.SaveChangesAsync();
          return new ObjectResult($"{sites.Name} added");
      }
  </code></pre>
  
  <p>How can I return a message to Ajax <code>"options.error"</code>?
  And <code>Name</code> + <code>Url</code> are <code>"[Required]"</code> in Model, but empty fields are still saved...</p>