<input type="file" id="file" name="file" />
<input type="button" class="button" value="Upload"
id="btnUpload">
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#btnUpload").click(function() {
var formdata = new FormData();
var files = $('#file')[0].files[0];
for(var i=0;files.length;i++)
{
formdata.append('files['+i+"]", files[i]);
}
$.ajax({
url: 'UploadFiles',
type: 'post',
data: formdata,
contentType: false,
processData: false,
success: function(result){
if(result){
alert('file uploaded successfully');
}
else{
alert('file upload failure');
}
},
});
});
});
</script>
C#
---------------------------------------------
public ActionResult UploadFiles(List<HttpPostedFileBase> files)
{
var fileList=files;
return json(true)
}
No comments:
Post a Comment