zoukankan      html  css  js  c++  java
  • mvc 上传文件

    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");
            }

  • 相关阅读:
    编程之美--2.13
    编程之美--2.17
    编程之美--3.8
    编程之美--3.7
    面试金典--9.3
    面试金典--9.2
    面试金典--9.1
    jq插件
    laravel controller
    laravel 登录验证
  • 原文地址:https://www.cnblogs.com/bignine/p/13771704.html
Copyright © 2011-2022 走看看