title: AJAX error not returning jqXHR.responseText.modelState when using custom dll
body: <p>I am using an asp.net webapi controller, and in my project I have a dll that I built myself.  The dll is being used to validate if the person that the user is typing in actually exists.</p>
  
  <p>Here is my controller method:</p>
  
  <pre><code>// POST: api/EventsAPI
  [ResponseType(typeof(Event))]
  public IHttpActionResult PostEvent(Event @event)
  {
      if (!ModelState.IsValid)
      {
          return BadRequest(ModelState);
      }
  
      if (@event.DateEndOfEvent &lt; @event.DateOfEvent) // successfully returns error.modelState (in view code)
      {
          ModelState.AddModelError("DateEndOfEvent", "End Date Cannot Be Before Start Date!");
          return BadRequest(ModelState);
      }
  
      if (!EmpData.IsValid(@event.PersonWorkedOne)) // returns error.modelState as undefined (in view code)
      {
          ModelState.AddModelError("PersonWorkedOne", "This person does not exist!");
          return BadRequest(ModelState);
      }
  
      if (!string.IsNullOrWhiteSpace(@event.PersonWorkedTwo))
      {
          if (!EmpData.IsValid(@event.PersonWorkedTwo)) // returns error.modelState as undefined (in view code)
          {
              ModelState.AddModelError("PersonWorkedTwo", "This persondoes not exist!");
              return BadRequest(ModelState);
          }
      }
  
      db.Event.Add(@event);
      db.SaveChanges();
  
      return CreatedAtRoute("DefaultApi", new { id = @event.Id }, @event);
  }
  </code></pre>
  
  <p>Now the two conditional statements above that have <code>EmpData</code>.. <code>EmpData</code> is from my dll.</p>
  
  <p>Here is the ajax code in my view:</p>
  
  <pre><code>$("form").data("validator").settings.submitHandler =
      function(form) {
          $.ajax({
              method: "POST",
              url: infoGetUrl,
              data: $("form").serialize(),
              success: function() {
                  toastr.options = {
                      onHidden: function () {
                          window.location.href = newUrl;
                      },
                      timeOut: 3000
                  }
                  toastr.success("Event successfully created.");
              },
              error: function (jqXHR, textStatus, errorThrown) {
                  var status = capitalizeFirstLetter(textStatus);
                  var error = $.parseJSON(jqXHR.responseText);
  
                  var modelState = error.modelState;
                  console.log(modelState);
                  $.each(modelState,
                      function (key, value) {
                          var id = "";
                          if (key === "$id") {
                              id = "#" +
                                  key.replace('$', '').substr(0, 1).toUpperCase() +
                                  key.substr(2);
                          } else {
                              id = "#" +
                                  key.replace('$', '').substr(0, 1).toUpperCase() +
                                  key.substr(1);
                              var status = capitalizeFirstLetter(textStatus);
                              console.log(key);
  
                              toastr.error(status + " - " + modelState[key]);
                          }
                          var input = $(id);
                          console.log(id); // result is #id
                          if (input) { // if element exists
                              input.addClass('input-validation-error');
                          }
                      });
              }
          });
      }
  </code></pre>
  
  <p>Now, in the controller when I purposefully test to get the error message concering the end date being before the start date, I receive <code>error.modelState</code>.  But when I purposefully test to get the error message saying that a person does not exist... I do not get <code>error.modelState</code>.. that returns as <code>undefined</code>.</p>
  
  <p>Does returning ModelState not work when using custom DLL?</p>
  
  <p>Any help is appreciated.</p>