简体   繁体   English

使用AngularJS和ASP.NET MVC上传文件

[英]File Upload with AngularJS and ASP.NET MVC

我是ASP.NET MVCAngularJS的新手,如何使用ASP.NET MVC Controller通过AngularJS Controller将文件(图像/ PDF / Doc)上传到服务器文件夹

you can use the angular-file-upload first install it: 您可以先使用angular-file-upload安装它:

bower install bower install angular-file-upload

then add it as dependency in your app. 然后将其作为依赖项添加到您的应用中。

angular.module('your-app-name', ['angularFileUpload']);

In your controller, inject the FileUploader service: 在您的控制器中,注入FileUploader服务:

angular.module('your-app-name').controller('ctrlName',
      ['$scope','FileUploader', function($scope, FileUploader) {
       $scope.uploader = new FileUploader({
                           url: 'server_url_here'
                   //you can add other configuration here like xsrf headers  
          });
      }]);

Then in your html: 然后在您的html中:

               Multiple
                <input type="file" nv-file-select="" uploader="uploader" multiple  /><br/>

                Single
                <input type="file" nv-file-select="" uploader="uploader" />

You can find a detailed explanation here: https://github.com/nervgh/angular-file-upload An example: https://github.com/nervgh/angular-file-upload/tree/master/examples/simple 您可以在此处找到详细的说明: https : //github.com/nervgh/angular-file-upload示例: https : //github.com/nervgh/angular-file-upload/tree/master/examples/simple

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM