首页 > Web开发 > 详细

asp.net MVC实现简单的上传功能

时间:2016-01-23 11:51:16      阅读:208      评论:0      收藏:0      [点我收藏+]
方法一:
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);
}

asp.net MVC实现简单的上传功能

原文:http://www.jb51.net/article/21179.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!