当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET MVC处理文件上传的小例子

ASP.NET MVC处理文件上传的小例子

2017年12月12日  | 移动技术网IT编程  | 我要评论

婆媳的战国时代全集,棒针毛衣编织花样视频,龙城岁月片尾曲

复制代码 代码如下:

<asp:content id="content2" contentplaceholderid="maincontent" runat="server">   
 
<h2>files uploaded to server</h2>   
 
<div id="dialog" title="upload files">     
  <% using (html.beginform("upload", "file", formmethod.post, new 

{ 

enctype = "multipart/form-data" 

}

)) 
  {%>

<br /> 
    <p><input type="file" id="fileupload" name="fileupload" size="23"/> ;</p><br /> 
    <p><input type="submit" value="upload file" /></p>     
  <% } %>   
</div> 
<a href="#" onclick="jquery('#dialog').dialog('open'); return false">upload file</a> 
</asp:content> 


然后,我们需要根据beginform中filecontroller和action(upload)在指定的controller中处理请求,参考如下代码:
复制代码 代码如下:

public void upload( 
{ 
foreach (string inputtagname in request.files) 
{ 
httppostedfilebase file = request.files[inputtagname]; 
if (file.contentlength > 0) 
{ 
string filepath = path.combine(httpcontext.server.mappath("../uploads") 
, path.getfilename(file.filename)); 
file.saveas(filepath); 
} 
} 
 
redirecttoaction("index", "file"); 
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网