简体   繁体   English

使用 Asp.net mvc 上传图片

[英]Upload Image using Asp.net mvc

My problem is when I try to upload an image in asp.net mvc, i try this method:我的问题是当我尝试在 asp.net mvc 中上传图像时,我尝试了这种方法:

        public ActionResult Create(Regional regional, HttpPostedFileBase صورة)
{
            

            if (ModelState.IsValid)
            {
  if (صورة != null)
                {
                    صورة.SaveAs(Path.Combine(Server.MapPath("~/1"), صورة.FileName));
                    regional.صورة = صورة.FileName;
                }

                db.Regionals.Add(regional);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(regional);
        }

and the input is:输入是:

<input type="file" id="صورة" name="صورة" accept="image/*" >

The problem is the name of the picture is saved in Database but the picture is not saved at the folder named "1", which is the Path.问题是图片的名称保存在数据库中,但图片没有保存在名为“1”的文件夹中,即路径。

please any help请任何帮助

 if (PersonalImage != null && PersonalImage.ContentLength > 0) 
            {
                string _ImageName = Path.GetFileName(_random + "-" + lastname + "-" + PersonalImage.FileName);
                string _Path = Path.Combine(Server.MapPath("~/Content/Uploads/Adherentes/Personalimages"), _ImageName);
                PersonalImage.SaveAs(_Path);
                adherent.PersonalImage = _ImageName;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM