首页 > Web开发 > 详细

mvc 上传文件

时间:2020-10-05 22:19:18      阅读:25      评论:0      收藏:0      [点我收藏+]

index.aspx

 <div>
        <% using (Html.BeginForm("Index", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
           {%>
        <input type="file" name="file" />
        <input type="submit" name="upload" value="提交" />
        <%} %>
    </div>

Controllers文件夹 - FileController.cs

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

mvc 上传文件

原文:https://www.cnblogs.com/bignine/p/13771704.html

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