I have an angularjs resource as seen below:
return $resource('/api/report',
{ },
{
save: { method: 'POST', url: '/api/fileupload/savefile', isArray: false },
});
My angularjs controller that uses this resource is below:
$scope.save = function () {
var reportFieldsSample = [{ Field: 'ff', Value: 'gg' }, { Field: 'aa', Value: 'dd' }];
Report.save({ reportParams: reportFieldsSample},
{ },
function (content) {
console.log(content);
});
My WebApiConfig for this route is:
config.Routes.MapHttpRoute(
"SaveFile",
"api/fileupload/savefile",
new { controller = "FileUpload", action = "SaveFile" },
new { httpMethod = new HttpMethodConstraint("POST") });
My mvc api controller that receives this is below:
[HttpPost]
public HttpResponseMessage SaveFile(IList<Parameter> reportParams)
{
//reportParams is null
}
Parameter class is declared in this way:
public class Parameter
{
public string Field { get; set; }
public string Value { get; set; }
}
The request enters my api controller but the reportParams argument of the controller is always null.
Can you help me point out the problem? Thanks
Report.save(reportFieldsSample,...)and see if it works