File Upload ASP.NET MVC 3.0

后端 未结 21 1001
无人共我
无人共我 2020-11-22 01:09

(Preface: this question is about ASP.NET MVC 3.0 which was released in 2011, it is not about ASP.NET Core 3.0 which was released in 2019)

I want to

21条回答
  •  别跟我提以往
    2020-11-22 01:48

    In Controller

     if (MyModal.ImageFile != null)
                        {
                            MyModal.ImageURL = string.Format("{0}.{1}", Guid.NewGuid().ToString(), MyModal.ImageFile.FileName.Split('.').LastOrDefault());
                            if (MyModal.ImageFile != null)
                            {
                                var path = Path.Combine(Server.MapPath("~/Content/uploads/"), MyModal.ImageURL);
                                MyModal.ImageFile.SaveAs(path);
                            }
                        }
    

    In View

    
    

    In Modal Class

     public HttpPostedFileBase ImageFile { get; set; }
    

    Create a folder as uploads in Content folder in project

提交回复
热议问题