title: how to call Json Method on textbox change event using jquery in asp.net mvc?
body: <p>I want to call a JSON method on my textbox change event using jquery.</p>
  
  <p>Below is how my JsonResult method looks like</p>
  
  <pre><code>public JsonResult GetUserName(string emailId)
  {
      string UserName = "";
      var query = (from u in DbContext.Users
                   where u.User_Email.ToLower() == emailId.ToLower()
                   select u).SingleOrDefault();
      if(query!=null)
      {
          UserName = query.User_FirstName +", "+query.User_LastName;
      }
      return Json(UserName, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>below is my view code</p>
  
  <pre><code>Email:&amp;nbsp;&lt;input type="text" id="txtEmail" /&gt;&lt;br /&gt;&lt;br /&gt;
  Name:&amp;nbsp;&lt;input type="text" id="txtName" /&gt;
  </code></pre>
  
  <p>below is the jquery code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              //$("#txtEmail").first().focus();
  
              $("#txtEmail").change(function () {
                  var emailId = $(this).val();
                  //$("#txtName").val(emailId);
                  $.ajax({
                      url: 'GetUserName',
                      type: 'POST',
                      data: JSON.stringify({ emailId: emailId }),
                      dataType: 'json',
                      contentType: 'application/json',
                      success: function (data) {
                          if (data != "" || data != null) {
                              $("#txtName").val(data);
                          }
                          else {
                              alert("Our system does not recognize this email. Please try again.");
                              $("#txtEmail").focus();
                          }
                      }
                  });
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>Note....My GetUserName JsonResult method belongs to my Default Controller.</p>
  
  <p>My jquery code is successfully getting executed on change event but the GetUserName method doesn't get called...please let me know what I am missing.</p>
  
  <p>Thanks,</p>