Edit: I would like this answer in jquery not a plain javascript ajax request.
I have looked at stackoverflow examples but none of them are working. Not sure what I am doing wrong.
I am posting a file back to an asp.net mvc controller.
Jquery
...
var uploadFile = document.getElementById('js-upload-files').files[0];
var $formData = new FormData();
$formData.append('file', uploadFile);
component.startUpload($formData);
...
startUpload : function (formData) {
DataConnectAjax.ajaxRequest($fileUploadUrl,
formData,
null,
"File Upload",
"Success",
null);
}
DataConnectAjax is just a normal jquery.ajax with a toast message at the end.
Controller
public ActionResult FileUpload()
{
var file = Request.Files["file"]; //file[0] same result null
...
return new BetterJsonResult();
}
file variable is null. I tried passing it in the constructor using HttpFileBase
Or something but still the same result.