title: ASP.NET MVC username availability check
body: <p>I have read a lot of step by step tutorials and still couldn't get my code to work, I went through the solutions on this site with no luck either, i don't know what i am doing wrong.</p>
  
  <p>I am using jQuery and want to find out whether the username "mark" is taken or not, I haven't even reached the database linkage yet.</p>
  
  <p>[HTML]</p>
  
  <pre><code>&lt;input id="user_name" name="user_name" onchange="UserCheck()" type="text" value="" /&gt;
  &lt;div id="status" /&gt;
  </code></pre>
  
  <p>[JS]</p>
  
  <pre><code>function UserCheck() {
      $("#status").html("Checking....");
      $.post("/user/check",
      { username: $("#user_name").val() },
      function (data) {
          if (data == 0) {
              $("#status").html("Available");
          }
          else {
              $("#status").html("Taken");
          }
      });
  }
  
  
  [Controller]
  
  public JsonResult check(FormCollection form)
  {
      System.Threading.Thread.Sleep(3000);
      string name = form["username"];
  
      if (name.Equals("mark")){
          return Json(1);
      } else {
          return Json(0);
      }
  }
  </code></pre>