C# 角度文件上载未将图像发布到C MVC控制器
我正在ASP.NET MVC应用程序中应用angular-file-uploader.js。我想在服务器上的文件夹中上载图像。在我的ProductTemplate controllerimage上接收图像时出现问题图像始终为空: 我的角度控制器:C# 角度文件上载未将图像发布到C MVC控制器,c#,asp.net-mvc,angularjs,angular-file-upload,C#,Asp.net Mvc,Angularjs,Angular File Upload,我正在ASP.NET MVC应用程序中应用angular-file-uploader.js。我想在服务器上的文件夹中上载图像。在我的ProductTemplate controllerimage上接收图像时出现问题图像始终为空: 我的角度控制器: MyApp.controller("MyController", ['$scope', '$upload', function ($scope, $upload) { $scope.imageFile = {}; $scope.sa
MyApp.controller("MyController", ['$scope', '$upload',
function ($scope, $upload) {
$scope.imageFile = {};
$scope.saveImage = function(images) {
var image = images[0];
image.upload = $upload.http({
url: '/ProductTemplate/FileUpload',
method: 'POST',
headers: {
'Content-Type': image.type
},
data: image
});
image.upload.then(function(response) {
...some code...
}, function() {
...some code...
});
};
}
Html页面:
<form>
<input type="file" accept="image/*" ng-file-select="" ng-model="imageFile" name="imageFile">
<button class="btn btn-default" ng-click="saveImage(imageFile)">Change image</button>
</form>
如何在后端控制器上获得正确的图像?我在寻找同一问题的解决方案时遇到了这个问题,因此,尽管最初的问题有点陈旧,我还是在回答: 我所做的是忽略自动绑定,只检查请求。文件:
foreach (string file in Request.Files) {
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
...
您是否尝试过public ActionResult FileUploadHttpPostedFileBase数据?@marianoc84是的,我尝试过,仍然为空。。。
foreach (string file in Request.Files) {
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
...