I would like to get a file from my upload control and send it to a validator action though an ajax call without doing a post.
-User select several files
-Clicks 'validate', that runs some checks and returns the result of the validation.
-If the validation is success, the Upload button will be displayed and it could be posted.
JAVASCRIPT
function OnValidateSurveyFiles() {
debugger;
var SurveyId = $('#SurveyID').val();
var file_1 = document.getElementById('surveyUploadcontrol_TextBox0_Input').files[0];
var serializedFile = JSON.stringify(file_1, null, 2);
var url = '/Survey/ValidateSurveyFiles';
$.ajax({
type: 'GET',
url: url,
data: { surveyFile: serializedFile },
success: function (result) {
//debugger;
//
},
error: function (result) {
// handle errors
location.href = "/Home/"
}
});
}
CONTROLLER
public ActionResult ValidateSurveyFiles(object surveyFile)
{
try
{
do something...
}
catch(Exception ex)
{
throw ex;
}
// I would like to return a json responde with html(partial view...) and a code with the validation's result.
return View("_");
}
Actually, file_1
looks like the following:
file_1: File
lastModified: 1442499299116
lastModifiedDate: Thu Sep 17 2015 16:14:59 GMT+0200 (Mitteleuropäische Sommerzeit)
name: "File.csv"
size: 1176120
type: "application/vnd.ms-excel"
webkitRelativePath: ""
__proto__: File
constructor: File()
lastModified: (...)
get lastModified: ()
lastModifiedDate: (...)
get lastModifiedDate: ()
name: (...)
get name: ()
size: (...)
type: (...)
webkitRelativePath: (...)
get webkitRelativePath: ()
__proto__: Blob
But the serialized file is just {}
Any idea how could I achieve the desired behavior?