文件上传之伪Ajax篇

iframe上传文件

接上篇:Ajax的最大特点就是无刷新(实际上是跳转),因此楼主想通过模拟Ajax的方式进行文件上传,也就是iframe上传文件

话不多说,直接上代码

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         }

后台代码和上篇是一样的,如果将<iframe name="send" style="display:none"></iframe>显示出来的话,还可以看到后台代码的返回值"Success",而且有错误的话,还能通过返回的iframe中的错误进行调试

这个上传方式最大的特点是没有一行javascript代码

到此,本篇结束,如有问题,欢迎指正

如有转载,请注明出处http://www.cnblogs.com/ones/p/4350592.html

原文地址:https://www.cnblogs.com/ones/p/4350592.html