File Upload ASP.NET MVC 3.0

后端 未结 21 996
无人共我
无人共我 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:39

    public ActionResult FileUpload(upload mRegister) {
        //Check server side validation using data annotation
        if (ModelState.IsValid) {
            //TO:DO
            var fileName = Path.GetFileName(mRegister.file.FileName);
            var path = Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
            mRegister.file.SaveAs(path);
    
            ViewBag.Message = "File has been uploaded successfully";
            ModelState.Clear();
        }
        return View();
    }
    

提交回复
热议问题