title: Update filter on every stroke
body: <p>I'm using C# in MVC 5. Trying to update my search results upon every key stroke. I've wrote what I think would be logical. In my View I wrote some Ajax to communicate with my post controller.</p>
  
  <pre><code>    @using (Html.BeginForm("Index", "Directory", FormMethod.Post))
      {
          &lt;p&gt;
              Search Employee: &lt;input type="text" name="userName" onkeyup="filterTerm(this.value);" /&gt;
  
  
          &lt;/p&gt;
  
      }
  
  &lt;script&gt;
      function filterTerm(value) {
          $.ajax({
              type: "POST",
              url: '@Url.Action("Index","Directory")',
              data: JSON.stringify({ userName: value }),
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (msg) {
                  $("#senderContent").html(msg.toString);
              },
              error: function () {
                  alert("not connected!");
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>and this is my controller:</p>
  
  <pre><code>        [HttpPost]
          public ActionResult Index(string userName)
          {
          /**********Establish Connection********/
          DirectoryEntry dir = createDirectoryEntry();
          DirectorySearcher search = new DirectorySearcher(dir);
  
          /****Refer to class constructor****/
  
  
          /********Create the List to store results in***************/
          List&lt;ADUser&gt; Users = new List&lt;ADUser&gt;();
          string DisplayName = "", SAMAccountName = "", Mail = "", Description = "", Department = "", TelephoneNumber = "", Fax = "";
  
          /*******Filter parameters************/
          search.Filter = "(&amp;((&amp;(objectCategory=Person)(objectClass=User)))(anr=" + userName + "* ))";
          SearchResultCollection searchresult = search.FindAll();
          search.PropertiesToLoad.Add("Displayname");
          search.PropertiesToLoad.Add("SAMAccountName");
          search.PropertiesToLoad.Add("Mail");
          search.PropertiesToLoad.Add("Description");
          search.PropertiesToLoad.Add("TelephoneNumber");
          search.PropertiesToLoad.Add("Fax");
          search.PropertiesToLoad.Add("Department");
  
           /*****************Filtering and populating the List****************/    
  
          if (searchresult != null)
          {
              foreach (SearchResult iResult in searchresult)
              {
                  ADUser userAttributes = new ADUser("", "", "", "", "", "", "");
  
                  foreach (string PropertyName in iResult.Properties.PropertyNames)
                  {
                      foreach (Object key in iResult.GetDirectoryEntry().Properties[PropertyName])
                      {
                          try
                          {
                              switch (PropertyName.ToUpper())
                              {
                                  case "DISPLAYNAME":
                                      DisplayName = key.ToString();
                                      userAttributes.Name = DisplayName;
                                      break;
  
                                  case "SAMACCOUNTNAME":
                                      SAMAccountName = key.ToString();
                                      userAttributes.DomainUserName = SAMAccountName;
                                      break;
  
                                  case "MAIL":
                                      Mail = key.ToString();
                                      userAttributes.EmailAddress = Mail;
                                      break;
  
                                  case "DESCRIPTION":
                                      Description = key.ToString();
                                      userAttributes.JobDescription = Description;
                                      break;
  
                                  case "TELEPHONENUMBER":
                                      TelephoneNumber = key.ToString();
                                      userAttributes.TelephoneNumber = TelephoneNumber;
                                      break;
  
                                  case "FAX":
                                      Fax = key.ToString();
                                      userAttributes.FaxNumber = Fax;
                                      break;
  
                                  case "DEPARTMENT":
                                      Department = key.ToString();
                                      userAttributes.Department = Department;
                                      break;
                              }
                          }
                          catch { }
                      }
                  }
  
                  Users.Add(userAttributes);
              }
  
              return View(Users);
          }
        return View();
       }
  </code></pre>
  
  <p>I've been monitoring what happens in Fiddler and it doesn't flag an issue, however the ajax error message keeps prompting. I've tested the value before being passed into ajax, and it is reading the value correctly. Just wondering why I'm getting prompted this error. Is it something in my Ajax? </p>