Angularjs ASP.NET MVC Web API原语Post未绑定
我有以下行动Angularjs ASP.NET MVC Web API原语Post未绑定,angularjs,asp.net-web-api,Angularjs,Asp.net Web Api,我有以下行动 [HttpPost] [Route("api/client/log")] public void SetClientLog([FromBody]string error) { ClientLogger.LogError(error); } 在angular中,我试图发布以下内容,其中log只是一个字符串 $http({ method: 'POST',
[HttpPost]
[Route("api/client/log")]
public void SetClientLog([FromBody]string error)
{
ClientLogger.LogError(error);
}
在angular中,我试图发布以下内容,其中log只是一个字符串
$http({
method: 'POST',
url: "api/client/log",
data: log,
headers: {'Content-Type': 'application/json'}
});
请确保在值前面加上=并设置正确的内容类型:
$http.post('api/Companies/Search', "="+$scope.query, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
})
.success(function (data, status) {
$scope.result = data;
})
.error(function (data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
这里的数据应该是一个对象…比如:data:{log:log}。