I'm having some issues serializing file inputs to pass via ajax to a MVC controller. I have a form that a user can upload one or more images. I want to then pass those image to a controller via ajax. The issue seems to be with the data
value. I'm getting the following error in the console window:
Uncaught ReferenceError: ImageUploads is not defined
Here is my code:
@using (Html.BeginForm("CreateGallery", "User", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="ImageUploads" id="upload-button" multiple="multiple" />
<button type="button" class="btn btn-default" id="create-thumbnails">Submit</button>
}
<script>
$(document).ready(function () {
$("#create-thumbnails").click(function () {
$.ajax({
type: 'POST',
url: '@Url.Action("DisplayThumbnails", "User")',
dataType: 'json',
data: ImageUploads,
success: function (data) {
alert(data);
},
error: function (ex) {
alert("error!");
}
});
})
});
</script>