发布于 2016-06-02 05:54:33 | 146 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


MVC中上传变得越来越容易,可是对于新手这个也还是不知道如何实现,以下方式实现MVC的上传功能,以下2种方法都是可以实现的,其中的代码参考了蓝色小铺和重典的文章。
方法一:
Home/Index.aspx中的代码
 
<% using (Html.BeginForm("up","Home",FormMethod.Post,new{enctype="multipart/form-data"})) {%> 
<input type="file" name="upfile" /> 
<input type ="submit" name ="upload" value ="上传" /> 
<%} %> 

Homecontroller中的代码 
[code] 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult up(HttpPostedFileBase upfile) 
{ 
if (upfile != null) 
{ 
if (upfile.ContentLength > 0) 
{ 
upfile.SaveAs("d:\\7.jpg"); 
} 
} 
return RedirectToAction("Index"); 
} 

方法二:



Home/Index.aspx中的代码
 
<form action="<%=Url.Action("upload2") %>" enctype="multipart/form-data" method="post"> 
<input name="up1" type="file" /><input type="submit" /> 
</form> 

Homecontroller中的代码
 
public ActionResult upload2(HttpPostedFileBase up1) 
{ 
up1.SaveAs("d:\\8.jpg"); 
return Content(up1.FileName); 
} 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务