title: How i can pass data to controller in ajax using asp MVC
body: <p>I have login form can user write username and password and i check if the username right or not i'm try to send the username to Home controller by ajax that's my controller code </p>
  
  <pre><code>          [HttpPost]
         public JsonResult ValidateUser(string username,string password)
      {
          using(var contxt=new EnglisCenterEntities())
          {
              var data = from a in contxt.Employee
                         where a.Username == username &amp;&amp; a.Passwords == password
                         select a.EmpName;
              string Empname = data.FirstOrDefault();
              if(data.Count()&gt;0)
              {
  
                  return Json(new { Success = true } ,JsonRequestBehavior.AllowGet);
              }
              else
              {
                  return Json(new { Success = false }, JsonRequestBehavior.AllowGet);
              }
          }
      }
  </code></pre>
  
  <p>and this is my ajax code </p>
  
  <pre><code>     &lt;script&gt;
          $(document).ready(function () {
  
                 $('#savedata').click(function (e) {
                             e.preventDefault();
                             var data = {
                                 username: function () { return $("#username").val(); },
                                 password: function () { return $("#password").val(); }
  
                             };
  
                             $.ajax({
                                 url: "/Account/validateuser",
                                 type: "POST",
                                 data: data,
                                 dataType: "json",
  
                                 success: function (response) {
  
  
  
  
  
                                         window.location.href = "@Url.Action("Index", "Home")";
  
                                     }
                                     else
                                         notifyBar();
                                         @*window.location.href = "@Url.Action("Login", "Account")";*@
                                 },
  
                                 error: function () {
                                     console.log('Login Fail!!!');
                                 }
                             });
                         });
  });
  </code></pre>
  
  <p>this code check if the user exist or not and it's working but i want to send the user name with redirect the Index action. How i can do that?</p>