File upload in MVC

前端 未结 2 1691
臣服心动
臣服心动 2020-12-30 13:21

I\'m trying to upload files within MVC. Most solution I saw on SO is use webform. I don\'t want to use that and personly prefer using streams. How do you implement RESTful f

2条回答
  •  离开以前
    2020-12-30 13:42

    public ActionResult register(FormCollection collection, HttpPostedFileBase FileUpload1){
    RegistrationIMG regimg = new RegistrationIMG();
    string ext = Path.GetExtension(FileUpload1.FileName);
    string path = Server.MapPath("~/image/");
    FileUpload1.SaveAs(path + reg.email + ext);
    regimg.Image = @Url.Content("~/image/" + reg.email + ext);
    db.SaveChanges();}
    

提交回复
热议问题