我正在使用 Flow.JS http://flowjs.github.io/ng-flow/进行文件上传。
我的要求是,我必须在一个保存按钮单击中发送以下数据
- 多个文件
- 两个字符串值以及文件。
以下方式工作正常。
上传ajax调用
$scope.UploadFiles = function (flows) {
var data = new FormData();
$.each(flows.files, function (i, flowfile) {
data.append('file' + i, flowfile.file);
});
data.append('message', $scope.Subject);
data.append('subject', $scope.Message);
$.ajax({
url: 'url\savedata',
data: files,
cache: false,
contentType: false,
processData: false,
type: 'POST'
});
}
还有我的 MVC 控制器
public JsonResult Savedata()
{
var httpRequest = System.Web.HttpContext.Current.Request;
if(httpRequest.Files.Count != 0)
{
var collection = 0;
foreach (string file in httpRequest.Files)
{
//manipulate file data
}
}
var message = httpRequest.Forms['message'];
var subject= httpRequest.Forms['subject'];
}
这一切都很好。我想知道是否有更好的方法来代替使用表单数据并可能使用数据模型发送所有这些数据,因为我需要一些 MVC 数据验证。