陈斌彬的技术博客

Stay foolish,stay hungry

HttpContext.Current.Request.Files后台取不到值的解决方法

前台是3个INPUT:

<INPUT   style= "WIDTH:   480px;   HEIGHT:   22px "   type= "file "   name= "File "   size= "60 "> 
<INPUT   style= "WIDTH:   480px;   HEIGHT:   22px "   type= "file "   name= "File "   size= "60 "> 
<INPUT   style= "WIDTH:   480px;   HEIGHT:   22px "   type= "file "   name= "File "   size= "60 "> 

在后台遍历

HttpFileCollection   files     =   HttpContext.Current.Request.Files; 
int   mm   =   files.Count;

结果:

mm   =0;

可能有几种原因,针对这些原因有如下方法:

一.form的enctype不对. 要加入enctype= "multipart/form-data "

二.手工加这个或者至少放一个runat= 'server '的file控件在窗体中.

三.form中用了AJAX,如果没有必要用,就不要随处放updatePannel控件

Resourece Reference