首页 > Web开发 > 详细

asp.net mvc下文件上传

时间:2014-09-05 14:11:51      阅读:162      评论:0      收藏:0      [点我收藏+]
典型的文件上传表单

<form action="/File" enctype="multipart/form-data"  

    method="post"/>

    <input type="file" name="file" />

    <input type="submit" name="upload" value="提交" />

</form>

文件上传操作

public ActionResult Index(HttpPostedFileBase file)

if (file != null)
{
               
     string strpath = Server.MapPath("~/files/"+ file.FileName);
     //获取文件路径
     if (file.FileName.LastIndexOf(@"\") > 0)
     {
          strpath = Server.MapPath("~/files/"+ file.FileName.Substring(file.FileName.LastIndexOf(@"\")));
     }
     file.SaveAs(strpath);//把图片保存在此路径中
     return Content("<script>alert(‘上传文件成功!‘);location.href=‘" + Url.Content("~/File") + "‘</script>");
}

asp.net mvc下文件上传

原文:http://www.cnblogs.com/shenlan/p/3957908.html

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