Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Pass the drag drop file to controller MVC

Hi Experts,

I am trying to drag and drop an file and then upload it on click of a button. I save the file in a hidden variable, So I can pass it when I submit the form.

jQuery('#dropZone').on('drop dragdrop', function (e) {
e.preventDefault(); 
 fileName = e.originalEvent.dataTransfer.files[0].name;
 file = e.originalEvent.dataTransfer.files[0];
jQuery('#dragDropLogoUpload').val(file);
jQuery(this).html(fileName);
});

Open in new window

#dragDropLogoUpload is the hidden variable

jQuery('#logoSubmit').click(function () {
jQuery('#dragDropLogoUpload').val();
jQuery('#frmSubmitLogoPost').submit();
}

Open in new window

When I Submit it goes to the controller -

public ActionResult SubmitLogo(HttpPostedFileBase dragDropLogoUpload) {
}

Open in new window

 But for some reason the value of "dragDropLogoUpload" is coming as null.

Please suggest what am I doing wrong?


Thanks in advance!

     

Avatar of Dorababu M
Dorababu M
Flag of India image

Did you tried this

$("#controlId").filedrop({
    fallback_id: 'btnUpload',
    url: '@Url.Action("SubmitLog")',
});

Open in new window

Check the article here 

https://www.aspsnippets.com/Articles/Implement-Drag-and-Drop-File-upload-in-ASPNet-MVC.aspx

ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial