title: how can i call web api Controller from ajax
body: <p>I am a beginner of ASP MVC with web api. </p>
  
  <p>By using below codes I tried to call a function which is written at the controller. For checking I used breakpoint so the control could not go to the controller so that I can not track actually what is going on.</p>
  
  <p>The given code explains how to  pass username and password to the controller:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function Login() {
  var Login = {};
  Login.username = document.getElementById("txtUserName").value;
  Login.password = document.getElementById("txtPassword").value;
  $.ajax({
  
  URL: 'api/Login/' + Login,
  type: 'POST',
  dataType: 'json',
  contentType: 'application/json; charset=utf-8',
  data: JSON.stringify(Login),
  success: function (data) {
  
  alert("Saved successfully");
  }
  })
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>This is the controller which i used to pass</p>
  
  <pre><code>public class LoginController : ApiController
  {
  [HttpPost]
  public void  Login(Login  login)
  {
  string user = login.UserName.ToString();
  string password = login.Password.ToString();
  }
  
  }
  </code></pre>