I have a file upload that does not use a form to upload a file, instead I want to upload it using ajax. I tried the following approach, but I can not transfer the file. It is zero. Please help. Below is my implementation.
HTML and jQuery function
<div id="Upload"> <input type="file" accept="application/x-shockwave-flash" id="virtualtourfile" enctype="multipart/form-data"/> <input type="button" value="Upload" id="btnUpload"/> </div> $('#btnUpload').click(function () { $.ajax({ url: "uploadvideo", type:'POST', data: $("#virtualtourfile:file"), success: function (data) { } }); });
controller
public ActionResult UploadVideo(HttpPostedFileBase file) { return Json("", JsonRequestBehavior.AllowGet); }
source share