我有一个 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
参数始终为空。你能帮我指出问题吗?谢谢