I am using the following code:
$http({
method: 'GET',
url: '/Admin/GetTestAccounts',
data: { applicationId: 3 }
}).success(function (result) {
$scope.testAccounts = result;
});
The code sends the following to my server:
http://127.0.0.1:81/Admin/GetTestAccounts
When this is received by my MVC controller:
[HttpGet]
public virtual ActionResult GetTestAccounts(int applicationId)
{
var testAccounts =
(
from testAccount in this._testAccountService.GetTestAccounts(applicationId)
select new
{
Id = testAccount.TestAccountId,
Name = testAccount.Name
}
).ToList();
return Json(testAccounts, JsonRequestBehavior.AllowGet);
}
It complains that there is no applicationId.
The parameters dictionary contains a null entry for parameter 'applicationId' of non-nullable type 'System.Int32' for method
Can someone explain why the applicationId is not being sent as a parameter? Previously I was doing this with the following non-Angular code and it worked just fine:
$.ajax({
url: '/Admin/GetTestAccounts',
data: { applicationId: 3 },
type: 'GET',
success: function (data) {
eViewModel.testAccounts(data);
}
});
$.param({ applicationId: 3 })?