这里我从角度服务中发送一个对象和一个文件:
$scope.addProject = function () {
{
var project = {};
project["Id"] = $scope.Id;
project["ProjectCode"] = $scope.ProjectCode;
var file = $scope.myFile;
projectModelService.saveProject(project,file)
.success(function (data) {
})
.error(function (xhr) {
$ngBootbox.alert('Error in saving data');
});
}
};
在我的角色服务中:
saveProject: function (project) {
var parameters = { project: project, file: file };
var fdata = new FormData();
fdata.append('file', file);
var param = { project: project, file: fdata.append('file', file) };
return $http({
url: '/Project/CreateProject',
method: 'POST',
data: project
// contentType: false, // Not to set any content header
// processData: false, // Not to process data
// transformRequest: angular.identity,
// headers: { 'Content-Type': undefined },
dataType: "json",
data: JSON.stringify(param)
})
},
并在我的Project / Createproject中:
public JsonResult CreateProject(Project project, HttpPostedFileBase file)
{
}
现在问题是我的HttpPostedFileBase文件在每种情况下都返回null。但是,如果我通过单个参数传递文件:
uploadProjectModelList: function (file) {
var fdata = new FormData();
var url = '/Project/UploadProjectFGModelListExcelFile';
fdata.append('file', file);
return $http.post(url, fdata, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
})
}
它显示了文件值但是每次使用它来传递多个参数时都会找到项目对象文件,但是项目对象为null。如何在MVC5中将多个参数作为对象和文件从ajax传递到asp.net控制器?