Reputation: 1903
I have ajax file uploader in my MVC3 application it's working absolutely fine in Firefox and chrome but it's not working in IE9 and IE8. when i have upload the file it give me wrong file name at server side in IE.
here is my up-loader code
<script type="text/javascript">
function InitializeUploader() {
Dname = [];
var uploader = new qq.FileUploader({
multiple: true,
element: document.getElementById('file-uploader'),
action: '@Url.Action("UploadDocument","Project")',
debug: true,
params: { id: $("#Id").val() },
onSubmit: function (id, fileName) {
},
onComplete: function (id, fileName, responseJSON) {
alert(responseJSON.fileName);
$("#DocumentName").val(responseJSON.fileName);
fileSize = responseJSON.size;
Dname.push(responseJSON.fileName);
type = responseJSON.type;
}
});
}
</script>
<form method="post" enctype="multipart/form-data" action="" style="margin-left: 4px;
margin-top: 0px;" id="documentUploadForm">
<div id="file-uploader">
<input type="file" id="uplodfile" />
<input class="button" type="button" value="Upload" id="UploadDocbtn" style="float: right;
width: 100px;" /></div>
</form>
server side Action
[HttpPost]
public ActionResult UploadDocument(string qqfile, int id)
{
// code for saving File
}
when i have run this in IE instead of giving file name in qqfile parameter, it give me file like System.Web.HttpPostedFileWrapper and file is also not save properly. i am not getting is this browser issue or IE prevent Some script. so how i can save file using ajax file up loader in IE?
Upvotes: 0
Views: 1029
Reputation: 12815
Actually, IE looks to be working exactly like it should.
And instead of UploadDocument(string qqfile, int id)
you should have UploadDocument(HttpPostedFileWrapper qqfile, int id)
File should be saved as qqfile.SaveAs("path to file")
Not clear what file name are you getting now. Possibly that is a result of conversion HttpPostedFile
to string and IE does not return some info required for that conversion to return file name instead of original object type.
Try to do something like this:
[HttpPost]
public ActionResult UploadDocument(System.Web.HttpPostedFileWrapper qqfile, int id)
{
qqfile.SaveAs("filename");
// code for saving File
}
It should work just fine in all browsers
Upvotes: 1