I am using Flow.JS http://flowjs.github.io/ng-flow/ for file upload.
My requirement is such that I will have to send the following data all in one save button click
- multiple files
- two string values alongwith the files.
The following way works fine.
Upload ajax call
$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'
});
}
And my MVC conroller
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'];
}
All this works fine. I want to know if there is a better way to do this instead of using form data and possibly send all this data using a data model instead, since I need that for some MVC data validations.