zoukankan      html  css  js  c++  java
  • MVC图片上传

     HTML代码:

    1  <form method="post" enctype="multipart/form-data">
    2  上传图片:<input type="file" accept=".jpg,.jpeg,.png,.gif"  id="imageUpLoad" name="file"/>
    3  <input type="button" id="mibtn" value="上 传" />
    4 </form>

    js代码:

    1  $("#mibtn").click(function () {
    2         this.form.setAttribute("action", "@Url.Action("Mproupdate", "CHome")");
    3         this.form.submit();
    4     });

    action:

     1 public ActionResult Mproupdate(HttpPostedFileBase file) {
     2  //转换只取得文件名,去掉路径。 
     3  string fileName = file.FileName;
     4                 if (fileName.LastIndexOf("\") > -1)
     5                 {
     6                     fileName = fileName.Substring(fileName.LastIndexOf("\") + 1);
     7                 }
     8                 //保存到相对路径下。 
     9                 string path = "/images/" + DateTime.Now.ToString("ddmmss") + fileName;
    10                 file.SaveAs(Server.MapPath(path));
    11  return RedirectToAction("Mpro", "CHome");
    12 }
  • 相关阅读:
    支持向量机(一)
    决策树(四)
    决策树(三)
    决策树(二)
    决策树(一)
    朴素贝叶斯(一)
    k近邻法(二)
    k近邻法(一)
    感知机
    mercurial 入门
  • 原文地址:https://www.cnblogs.com/zblc2016/p/6180493.html
Copyright © 2011-2022 走看看