Asp.net MVC 中的一个文件上传

来源:互联网 发布:硬盘坏了怎么恢复数据 编辑:程序博客网 时间:2024/05/16 15:45

 

文件的上传

下面来说一下与本篇本无关的话题就是文件的上传,我这里也不多做解释了,代码就是最好的语言。

View:

 

1: <form action="<%=Url.Action("Process") %>" enctype="multipart/form-data" method="post">

   2: <input name="up1" type="file" /> <input type="submit" />
   3: </form>

Action(Process):

   1: public ActionResult Process(HttpPostedFileBase up1)
   2: {//参数名与name名一致即可
   3:     up1.SaveAs(Server.MapPath("~/" + up1.FileName));
   4:     return Content(up1.FileName);
   5: }

 

 

 

原创粉丝点击