我已使用angular file-model将我的图像上传到本地文件夹并使用json返回路径,但我无法保存到数据库的路径。请帮我解决这个问题。我使用.success方法将响应数据返回到隐藏字段以将其存储在数据库中,但它显示错误:“无法读取未定义的属性'成功'。
services.js:
View rootView = inflater.inflate(R.layout.fragment_main, container, false);;
ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
listView.setAdapter(mForecastAdapter);
return rootView ;
Controller.js:
service.UploadFile = function (file) {
var fd = new FormData();
fd.append('file', file);
$http.post('/Empdet/UploadFile', fd, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
})
.success(function () {
})
.error(function () {
});
}
return service;
CreateNewEmployee.cshtml:
$scope.UploadFile = function () {
console.log('UploadFile');
console.log($scope.Empdet.PhotoFile);
EmployeeFactory.UploadFile($scope.Empdet.PhotoFile).success(function (response) {
console.log('response.IsSuccessful');
console.log(response.Data);
$scope.IsSuccessful = response.IsSuccessful;
if ($scope.IsSuccessful) {
$scope.PhotoText = response.Data;
console.log('$scope.PhotoText');
console.log($scope.PhotoText);
$scope.CanClearMessage = true;
} else {
$scope.SuccessMessage = '';
$scope.ErrorMessage = response.ReasonForFailure;
$scope.CanClearMessage = true;
}
}
)};
EmpdetController.cs:
<tr>
<td style="text-align: left;">
<label class="labelsytle">
PhotoFile
</label>
</td>
<td style="text-align: left;">
<input class="form-control" type="file" file-model="Empdet.PhotoFile" style="border-radius: 5px;"/>
<td><button class="btn btn-primary" ng-click="UploadFile()" style="border-radius: 5px; font-family: Consolas;">UPLOAD</button></td>
</td>
</tr>
<tr>
@*<td style="text-align: left;">
<label class="labelsytle">
PhotoText
</label>
</td>*@
<td style="text-align: left;">
<input class="form-control" type="hidden" name="search" ng-model="Empdet.PhotoText" placeholder="Enter PhotoText" style="border-radius: 5px;" />
</td>
</tr>
答案 0 :(得分:0)
使用.then
功能代替.success
将以下代码
替换为您的.success
和.error
代码块
.then(function (d) {
//Success callback
}, function (error) {
//Failed Callback
alert('Error!');
});