File Upload-pseudo Ajax
Iframe Upload File
Next article: The biggest feature of Ajax is that it does not need to be updated. Therefore, the author wants to upload files by simulating Ajax, that is, uploading files through iframe.
Let's just talk about the code.
HTML:
1 <iframe name = "send" style = "display: none "> </iframe> 2 3 <form action ="/home/receiveAjax/"target =" send "method =" post "enctype =" multipart/form-data "> 4 <input type = "text"/> 5 <input type = "file" name = "file" id = "file"/> 6 <input type = "submit"/> 7 </form>
C #:
1 [HttpPost] 2 public ActionResult receiveAjax (string s1) 3 {4 HttpPostedFileBase file = Request. Files [0]; 5 return Content ("Success"); 6}
The background code is the same as the previous one. If <iframe name = "send" style = "display: none"> </iframe> is displayed, you can also see the return value of the background code "Success". If there is an error, You can debug it through the error in the returned iframe.
The biggest feature of this upload method is that there is no javascript code line.
At this point, this article is over. If you have any questions, please correct me.