On my front end, I have a simple button:
<input class="btn" value="Something" ng-click="doStuff('myNameisEarl')" />
My Angular.js is as follows:
$scope.doStuff = function (name) {
$http.post('/api/callToApi', name)
.then(function (response) {
// Do something with response
}, function () {
console.log("Failure");
});
}
Then my back end C# Controller is:
[HttpPost("api/callToApi")]
public IActionResult Get(string name)
{
return Ok(_context.MyDBTable.Where(a => a.Name.Equals(name)));
}
Unfortunately, when I pass in name from my angular code to the C# function, string name is null.
Why is that? What's going wrong here?