Note that there are some explanatory texts on larger screens.

plurals
  1. POUploaded file is empty in controller
    primarykey
    data
    text
    <p>I'm trying to upload a file with ajax, jquery and formdata without doing a refresh. Unfortunately, when i am trying to read the file in my controller it says that the file is empty and i have no idea why.</p> <p>The div "uploadForm" is the form itself.</p> <p>JQuery:</p> <pre><code> $("#submitImage").click(function (event) { event.preventDefault(); $('#uploadImage #submitImage').val('Uploading File..'); var formData = new FormData($('#uploadForm')); $.ajax({ url: "Upload", data: formData, processData: false, contentType: false, type: 'POST', success: function (data) { alert(data); } }); }); </code></pre> <p>Html:</p> <pre><code> @using (Html.BeginForm("Index", "Upload", FormMethod.Post, new { enctype = "multipart/form-data", @id="uploadForm"})) { &lt;input type="submit" value="Upload Image" id="submitImage"/&gt; &lt;input type="file" name="file" id="bannerImage" value="Choose file" /&gt; } </code></pre> <p>Controller:</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] [HttpPost] public ActionResult Index(HttpPostedFileBase file) { Functions Functions = new Functions(); string Filename = Functions.GenerateUniqueFileName(); if (file == null) { ViewBag.Test = "Ajax call complete, but the file is empty"; } else { ViewBag.Test = "Ajax call complete, and the file isn't empty!"; } return View(); } } </code></pre> <p>Live demo: <a href="http://upload.jamieknoef.nl/" rel="nofollow">http://upload.jamieknoef.nl/</a> (You only need to use the choose file &amp; upload file buttons)</p> <p><strong>Edit: Fixed, see my other post for the answer!</strong></p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload