I have two input type file controls in my view page . One is for Avatar and the other is for profile image. And I am getting both images in code behind. Here is my AngularJS controller
var app = angular.module('ProfileModule', []);
app.controller('ProfileController',['$scope','$http', function ($scope,$http) {
$scope.user = {};
$scope.files = [];
var formData = new FormData();
$scope.LoadFileData = function (files) {
for (var file in files) {
formData.append("file", files[file]);
}
};
$scope.submit = function () {
$http({
url: "/Profiles/Edit",
method: "POST",
headers: { "Content-Type": undefined },
transformRequest: function (data) {
formData.append("user", angular.toJson(data.user));
//for (var i = 0; i < data.files.length; i++) {
// formData.append("files[" + i + "]", data.files[i]);
//}
return formData;
},
data: { user: $scope.user }
})
.success(function (response) { });
}
}]);
Here are the two controls
<input id="selector" type="file" onchange="angular.element(this).scope().LoadFileData(this.files)" accept="image/*">
<input id="selector" type="file" onchange="angular.element(this).scope().LoadFileData(this.files)" accept="image/*">
Here is my MVC controller
public ActionResult Edit(string user, HttpPostedFileBase[] files)
{}
I am getting rest model value in string and later parsing that to model but images file showing null in files so I am getting them in Request.Files . What edit should I do to get that images file in the array.