// <input type="file" accept="image/*" id="img-input">
// <img id="preview"/>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#preview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
} else {
$('#preview').attr('src', '');
}
}
$("#img-input").change(function() {
readURL(this);
});
var formData = new FormData();
formData.append('file', $('#myfile')[0].files[0]); // myFile is the input type="file" control
var _url = '@Url.Action("UploadFile", "MyController")';
$.ajax({
url: _url,
type: 'POST',
data: formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success: function (result) {
},
error: function (jqXHR) {
},
complete: function (jqXHR, status) {
}
});