web api put识别查询字符串但不识别正文
当我将用户作为查询字符串传递(使用$ http中的参数)并设置web api方法在uri中查找它们时,一切都很好。 但是当我按照下面的方式传递它们时,用户显示为null。 我在这里失踪了什么?
角度函数
scope.saveChanges = function () { // create array of user id's var users = []; angular.forEach(scope.usersInRole, function (v, k) { users.push(v.Key); }); var data = { user: users }; var token = angular.element("input[name='__RequestVerificationToken']").val(); // put changes on server http({ url: config.root + 'api/Roles/' + scope.selectedRole + '/Users', method: 'PUT', data: data, contentType: "application/json; charset=utf-8", headers: { "X-XSRF-Token": token }, xsrfCookieName: '__RequestVerificationToken' }).success(function (result) { // notify user changes were saved angular.element('#myModal').reveal({ closeOnBackgroundClick: false }); }); };
web api行动
public HttpResponseMessage Put(HttpRequestMessage request, [FromUri]string role, [FromBody]string[] user) { return request.CreateResponse(HttpStatusCode.NoContent); }
尝试: data: users
而不是data: data
。
在asp.net api中, 整个请求体绑定到一个参数。 因此,操作方法参数中的[FromBody]
不能包含多个参数。 只有一个=>我们不需要在请求体中指定属性名称。
- ASP.NET MVC和Angularjs一起+ ASP.NET Web API
- 使用ASP.Net MVC RouteConfig的AngularJS Ui-Router。 它是如何工作的?
- entity framework在db.SaveChanges()期间创建新数据行
- 通过Angular进行基本身份validation,为什么抛出错误401
- 在Asp.net Web API中处理CORS预检
- AngularJs和ASP.NET MVC 5-ng-model覆盖文本框值
- 是否可以在ASP.NET Web API和SPA中使用基于cookie的身份validation?
- Angular $ http错误响应statusText始终未定义
- 如何通过angularJS和webaAPI2下载内存流对象