我使用以下代码:
$http({ method: 'GET',url: '/Admin/GetTestAccounts',data: { applicationId: 3 } }).success(function (result) { $scope.testAccounts = result; });
http://127.0.0.1:81/Admin/GetTestAccounts
当我的MVC控制器收到此信息时:
[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); }
它抱怨没有applicationId.
The parameters dictionary contains a null entry for parameter ‘applicationId’ of non-nullable type ‘System.Int32’ for method
有人可以解释为什么applicationId不作为参数发送?以前我正在使用以下非角度代码,它工作得很好:
$.ajax({ url: '/Admin/GetTestAccounts',data: { applicationId: 3 },type: 'GET',success: function (data) { eviewmodel.testAccounts(data); } });
如果你不想使用jQuery的$.param,你可以使用序列化对象的$http的param域.
原文链接:https://www.f2er.com/angularjs/142794.htmlvar params = { applicationId: 3 } $http({ url: '/Admin/GetTestAccounts',method: 'GET',params: params });