I have an Angular view and controller which collect user data from several forms. The data from the Angular code is then passed to several C# classes. The user data currently comes into C# as an IEnumerable<> object; this collection has a type of FormData, which is a custom class of 6 properties (no methods). All user data is stored in the 'Data' property of the FormData class via the IEnumerable<> object, and the 'Data' property is a string. Because 'Data' is a string, any file uploads that enter the C# come in as a string, not an actual file. Here's the View:
<div data-ng-controller="customFormController as formController" data-ng-init="formController.init(@Model.Form, '@Model.EmailResults', '@Model.EmailTo')">
<div data-ng-if="!formController.loading && !formController.submitted" mc-form data-on-submit="formController.submit(model, formData)" data-on-file-select="formController.fileSelect(e)">
<!--form fields are added dynamically via a separate set of Angular/C# controllers-->
</div>
</div>
Here's part of the controller:
self.submit = function (model, formData) {
var deferred = $q.defer();
var formPostData = {
formId: self.formId,
data: formData,
emailData: self.emailData,
emailTo: self.emailTo,
saveData: true
};
customFormService.postData(formPostData).then(function (result) {
self.submitted = true;
deferred.resolve(result);
window.location.href = '#form-' + self.formId;
// push any files
if (typeof window.FormData !== 'undefined' && result) {
var formData = new FormData();
if (fileList && fileList.length) {
for (var f in fileList) {
if (fileList.hasOwnProperty(f)) {
formData.append('file', fileList[f]);
console.log('Files added to formData property');
}
}
customFormService.postFiles(result.data, formData);
console.log('files posted to customFormService');
}
}
}, function (err) {
deferred.reject(err);
});
return deferred.promise;
}
//Here's the file-select method:
self.fileSelect = function (e) {
for (var x = 0; x < e.length; x++) {
fileList.push(e[x]);
}
}
Sorry, that was long-winded. Is there a way to grab the actual file object (not just a JSON string) using the Angular controller and access that object in C#? Thanks!