【发布时间】:2012-12-25 23:47:45
【问题描述】:
我在我的页面中使用AngularJS,我有一个疑问:当我使用我的表单发布时,如何将一些选定的文件传递给我的 ASP.NET MVC 3 控制器? 看看这个:
我的表格:
<form enctype="multipart/form-data" ng-controller="FilesController" ng-submit="submitingForm()">
<div>
Choose the file:
<input type="file" onchange="angular.element(this).scope().setSelectedFile(this)" />
</div>
<input type="submit" value="Confirm" />
</form>
还有 AngularJS 控制器:
var module = angular.module('application', []);
(function (ang, app) {
function FilesController($scope, $http) {
$scope.setSelectedFile = function (element) {
$scope.$apply(function($scope) {
$scope.selectedFile = element.files[0];
});
};
$scope.submitingForm = function() {
$http.post(url, ???????).success(function() {
// How to pass that selected file for my ASP.NET controller?
});
}
}
app.controller("FilesController", FilesController);
})(angular, module);
谢谢!!!
【问题讨论】:
标签: asp.net-mvc-3 file-upload angularjs