Adding a image to database in ASP.NET MVC 5

asp.net-mvc c# entity-framework

Accepted Answer

HTML; it has nothing to do with MVC or C#. I also want to express my gratitude for the question's thoroughness and for including so much information.

You must add enctype="multipart/form-data" to your form.

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form", enctype="multipart/form-data" }))
4
1/13/2015 1:48:20 PM

Popular Answer

  public ActionResult AddImage(Brand model,HttpPostedFileBase image1)
        {
            var db = new H_Cloths_SaloonEntities();
            if (image1!=null)
            {

                model.Brandimage = new byte[image1.ContentLength];
                image1.InputStream.Read(model.Brandimage,0,image1.ContentLength);
            }
            db.Brands.Add(model);
            db.SaveChanges();
            ViewBag.Path = "image uploaded Successfully...!";
            return View(model);

        }


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow