title: Posting Data to asp.net core controller using angularjs
body: <p>I am new to Asp.net core. I am trying to make simple login page which connects to database. But for some reason I can't post username and password to controller.</p>
  
  <p>Controllers/HomeController.cs</p>
  
  <pre><code>namespace WebApplication12.controllers
   {
  public class HomeController : Controller
  {
      public ActionResult Index()
      {
          MysqlConnector test = new MysqlConnector();
          return View(test);
      }
  
  
  
  
      public string test_name { get; set; }
      public string test_role { get; set; }
  
      private MySqlConnection connectio;
  
      [HttpPost]
      public JsonResult PostData(string User, string Pass)
      {
          connect(User,Pass);
          MySqlCommand query = new MySqlCommand();
          query.Connection = connectio;
          query.CommandText = string.Format("Select * from users");
  
          MySqlDataReader reader = query.ExecuteReader();
  
          reader.Read();
          try
          {
              test_name = reader["user"].ToString(); //reader.getString(1);
              test_role = reader["role"].ToString();
              reader.Close();
              return Json(new {success=true , user=test_name});
  
          }
          catch (Exception err)
          {
              test_name = err.ToString();
              test_role = err.ToString();
              reader.Close();
              return Json(new { success = false });
          }
  
  
  
      }
  
  
      private void connect(string user,string pass)
      {
  
  
          string ConnectionString =  string.Format("server=localhost ;database=xdata; uid={0} ; pwd={1}",user,pass);
  
          connectio = new MySqlConnection(ConnectionString);
          connectio.Open();
  
  
  
      }
  }
  </code></pre>
  
  <p>login.html</p>
  
  <pre><code> &lt;p&gt;&lt;input ng-model="username" value="Username"/&gt;&lt;/p&gt;
   &lt;p&gt;&lt;input ng-model="password" value="Password"/&gt;&lt;/p&gt;
  &lt;p&gt;&lt;button type="button" ng-click="submit(username,password)"&gt;Click to Submit&lt;/button&gt;&lt;/p&gt;
  </code></pre>
  
  <p>angular code</p>
  
  <pre><code> $http.post('/HomeController/PostData/', {
          'User': user,
          'Pass': pass
  
      })
  
      .success(function (data) {
          $scope.something = data;
          console.log(data);
  
      }).error(function (response) {
  
          alert("Fail");
  
      });
  </code></pre>
  
  <p>When I click the button, on the console, it shows the entire html. Apparently there is an error while posting. Thanks in advance. ( error at "HomeController/PostData/ (?)   )</p>