【问题标题】:File Upload with AngularJS and ASP.NET MVC使用 AngularJS 和 ASP.NET MVC 上传文件
【发布时间】:2017-08-05 13:57:50
【问题描述】:

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

【问题讨论】:

    标签: c# angularjs asp.net-mvc asp.net-web-api


    【解决方案1】:

    您可以使用 angular-file-upload 首先安装它:

    bower install bower install angular-file-upload
    

    然后将其作为依赖项添加到您的应用中。

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

    在您的控制器中,注入 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  
              });
          }]);
    

    然后在你的html中:

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

    您可以在此处找到详细说明: https://github.com/nervgh/angular-file-upload 一个例子: https://github.com/nervgh/angular-file-upload/tree/master/examples/simple

    【讨论】:

    • 感谢您的回复,您能帮我处理一下 ASP.NET MVC 控制器吗
    • 嗨,很抱歉回复晚了......也许我可以指导你找到一个好的资源/专家,他已经很好地解释了将 Angular 与 asp.net 集成以及遵循的最佳实践.检查此链接:www.bradoncode.com/blog/2012/11/the-code-review-aspnet-10-years-on-2.html
    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 2012-12-25
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2010-12-31
    • 1970-01-01
    相关资源
    最近更新 更多