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

    VIEW 代码

    @using (Html.BeginForm("Upload", "UploadFile", FormMethod.Post, new { enctype = "multipart/form-data" }))

    {   

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

     <input type="submit" value="OK" />

     }

    Controller 代码

              [HttpPost]        

     public ActionResult Upload(HttpPostedFileBase file)      

     {            

            if (file != null && file.ContentLength > 0)    

                {           

                   // extract only the fielname                 

                   var fileName = Path.GetFileName(file.FileName);       

                  // store the file inside ~/App_Data/uploads folder             

                  var path = Path.Combine(Server.MapPath("~/Content/File"), fileName);    

                   file.SaveAs(path);                

             }             

             // redirect back to the index action to show the form once again         

             return RedirectToAction("Index");     

     }

  • 相关阅读:
    html input在标签内设置禁止输入空格
    JS判断json是否为空
    python常见问题集锦
    Node.js入门教程合集
    Vue入门教程合集
    将博客搬至CSDN
    Python 使用PyInstaller打包发布
    VSCode开发Python
    Python 验证码解析
    IntelliJ IDEA常见问题及使用技巧(持续更新)
  • 原文地址:https://www.cnblogs.com/a546558309/p/2417583.html
Copyright © 2011-2022 走看看