. Net mvc4 + ajaxfileupload. js solves the problem of the pop-up Download Dialog Box in IE browser, ajaxfileupload. js
Abstract: Everyone encounters different problems. I have not solved my problems after finding a large circle on the Internet! This problem is solved because my environment is shown in the title.
Main problem: the setting of the Response Header
Controller:
[HttpPost] public ContentResult UploadFile(string user = WinTabConst.Space, int type = ConfigConst.Zero, string imgType = WinTabConst.Space, int objId = ConfigConst.Zero, DateTime? createDateTime = null) { HttpPostedFileBase imgFile = Request.Files["imgFile"]; AttachmentBLL attachmentBll; if (!string.IsNullOrEmpty(user)) attachmentBll = new AttachmentBLL(user); else attachmentBll = new AttachmentBLL(); int userId = 0; users userModel = attachmentBll.CurUser; if (user != null) userId = userModel.UserID; return Content(JavascriptHelper.JsonSerializer.Serialize(attachmentBll.UploadFile(true, "", imgFile, type, imgType, objId, userId, createDateTime))); }
Js:
$. AjaxFileUpload ({url: "/Companies/attachment/UploadFile", data: {"objId": objId, "createDateTime": createDateTime, "dir": "", "type ": "2", "userid": UserID, "user": $. cookie ('logininfo')}, type: "post", secureuri: false, dataType: "text", fileElementId: "imgFile", success: function (data) {if (data! = Null & data = "") {// The result is that the format is json and the data received by IE is "", but the figure shows a successful transfer problem $ (". uploadImg "). hide (); $ (". mask "). hide ();} else if (data! = Null & data. error = 0) {// my correct execution method $ (". uploadImg "). hide (); $ (". mask "). hide ();} else {AlertAlert ("Upload Failed! ") ;}}, Error: function (e) {$. messager. alert (" prompt "," Operation error! ");}});
In ajaxfileUploadjs, jQuery (form) submit (); ie does not go to the background, and other browsers do. Why?
File selected files are directly triggered by file files, which I have encountered before:
Create a file control when a button is clicked, and then file. click ()
This method is fine for browsers other than IE, but you must click file in IE to upload the file successfully. I will not explain the security issues that everyone knows.
Solution: create a file and click the file control to trigger the file selection. If you think the file looks bad, OK is transparent and then set the style you want, you should understand it as a smart person. Two images: (this is irrelevant to the background)
Images cannot be uploaded all the time. If you want to, I will send you an email!
Note: If you don't give a score for such a hard job, you won't be able to give it a score !!!