The problem is in IE when I submit a file the ajax loader gif doesn't spin while the file is loading. The page is locked even though its supposed to be Ajax. In FF the image does spin. In both browsers, the built in loading indicator spins while the file is uploading. I've tried experimenting with preventDefault() in IE which prevents the browser loading indicator from spinning, and the gif spins, but nothing is posted to the server even though it still hits the javascript block that should be uploading the file. Unfortunately I'm stuck with just JQuery, cannot deploy any other third party plugins or libraries. Also, can't use HTML5, client has a mix of older and newer browsers. The code:
EDIT: I can get the image to spin now, and hit the controller, with the code below. However, in the controller Request.Files is empty! In the original code, the original ajax call was posting to controller/controller/upload file when preventdefault was called, and returned a 404. So I chnaged the path in the ajax call from client/uploadfile to uploadfile and now it hits the controller. Makes no sense why the request files is empty though.
$("form").submit(function (event) {
event.preventDefault()
});
$('#submit').click(function (data) {
$('#progImg').fadeTo(0, 1);
$(".mgnlft").css("visibility", "visible");
var filename = $("#file").val();
$.ajax({
type: "POST",
url: "uploadFile",
enctype: 'multipart/form-data',
data: {
file: filename
},
success: function () {
$('#progImg').fadeTo(0, 0);
}
});
//data.preventDefault()
});
<input name="File" type="file" style="width: 380px;" id="file" />
<p>
<input type="submit" value="Upload" id="submit"/>
</p>
controller:
public ActionResult uploadFile(string file)
{
var destinationFolder = mypath;
foreach (var name in Request.Files)
{
var postedFile = Request.Files[0];
if (postedFile.ContentLength > 0)
{
var fileName = Path.GetFileName(postedFile.FileName);
var path = Path.Combine(destinationFolder, fileName);
postedFile.SaveAs(path);
}
}
return View("submitfile");
}