iframe上传文件
接上篇:Ajax的最大特点就是无刷新,因此楼主想通过模拟Ajax的方式进行文件上传,也就是iframe上传文件
话不多说,直接上代码
HTML:
1 | 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>
|
Salin selepas log masuk
C#:
1 | 1 [HttpPost]2 public ActionResult receiveAjax(string s1)3 {4 HttpPostedFileBase file = Request.Files[0];5 return Content( "Success" );6 }
|
Salin selepas log masuk
后台代码和上篇是一样的,如果将显示出来的话,还可以看到后台代码的返回值"Success",而且有错误的话,还能通过返回的iframe中的错误进行调试
这个上传方式最大的特点是没有一行javascript代码
到此,本篇结束,如有问题,欢迎指正