Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 角度文件上载未将图像发布到C MVC控制器_C#_Asp.net Mvc_Angularjs_Angular File Upload - Fatal编程技术网

C# 角度文件上载未将图像发布到C MVC控制器

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

我正在ASP.NET MVC应用程序中应用angular-file-uploader.js。我想在服务器上的文件夹中上载图像。在我的ProductTemplate controllerimage上接收图像时出现问题图像始终为空:

我的角度控制器:

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) 
        ...