【发布时间】:2013-12-17 00:18:07
【问题描述】:
我有一个 angularjs 资源,如下所示:
return $resource('/api/report',
{ },
{
save: { method: 'POST', url: '/api/fileupload/savefile', isArray: false },
});
我使用此资源的 angularjs 控制器如下:
$scope.save = function () {
var reportFieldsSample = [{ Field: 'ff', Value: 'gg' }, { Field: 'aa', Value: 'dd' }];
Report.save({ reportParams: reportFieldsSample},
{ },
function (content) {
console.log(content);
});
我的这条路线的 WebApiConfig 是:
config.Routes.MapHttpRoute(
"SaveFile",
"api/fileupload/savefile",
new { controller = "FileUpload", action = "SaveFile" },
new { httpMethod = new HttpMethodConstraint("POST") });
我收到这个的 mvc api 控制器如下:
[HttpPost]
public HttpResponseMessage SaveFile(IList<Parameter> reportParams)
{
//reportParams is null
}
参数类是这样声明的:
public class Parameter
{
public string Field { get; set; }
public string Value { get; set; }
}
请求进入我的 api 控制器,但控制器的 reportParams 参数始终为空。
你能帮我指出问题吗?谢谢
【问题讨论】:
-
你可以尝试以
Report.save(reportFieldsSample,...)发送数据,看看是否有效 -
它有一个错误:TypeError: Object doesn't support property or method 'push'
-
客户端或服务器端错误?
-
客户端..我在浏览器的控制台日志中发现了错误
-
TypeError: 对象不支持属性或方法'push';副本(localhost:54429/Scripts/angular.js:826:9);在资源 (localhost:54429/Scripts/angular-resource.js:433:9)
标签: angularjs asp.net-web-api asp.net-web-api-routing angular-resource