I currently have a C# controller with a method AddOne():
public void AddOne(int num)
{
using (cnxn)
{
using (SqlCommand sc = new SqlCommand("INSERT INTO Employees VALUES('this','works'," + num +")", cnxn))
{
cnxn.Open();
sc.ExecuteNonQuery();
cnxn.Close();
}
}
}
And then for my Angular code, I have a controller EntriesController:
var EntriesController = function ($scope, $stateParams, $location, $http) {
$scope.Entries = {
num: 10
};
$scope.addValues = function () {
$http.post('Data/addOne', { num });
}
}
EntriesController.$inject = ['$scope', '$stateParams', '$location', '$http'];
I have the EntriesController's addValues() function registered to a button on a view which does send insert values into my database if I hardcode them like this:
AddOne:
public void AddOne()
{
using (cnxn)
{
using (SqlCommand sc = new SqlCommand("INSERT INTO Employees VALUES('this','works',10)", cnxn))
{
cnxn.Open();
sc.ExecuteNonQuery();
cnxn.Close();
}
}
}
and the addValues():
$scope.addValues = function () {
$http.post('Data/addOne');
}
How can I pass data from my Angular's post to my C#'s controller? Thanks, everyone!