Why I cannot save images in a folder when I’m creating an product..?
This is the controller:
` [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Product pro, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath(“/Content/assets/ProductImage/”), fileName);
file.SaveAs(path);
pro.Image = fileName;
}
db.Products.Add(pro);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(pro);
}
`
and this is the view:
`
@foreach (var produkti in Model)
{
<div class="col-xl-4 col-lg-4 col-md-6 col-sm-6">
<div class="single-popular-items mb-50 text-center">
<div class="popular-img">
<img src="@Url.Content("~/Content/assets/ProductImage/" + produkti.Image)" alt="Product Image" />
<div class="img-cap">
<span>Add to cart</span>
</div>
</div>
<div class="popular-caption">
<h3><a href="product_details.html">@produkti.Name</a></h3>
<span>@produkti.Price</span>
</div>
</div>
</div>
}
</div>
</div>
</div>
`
Other details are showing (Name,Price) just image it isn’t…
I have tried changing the path… Inserting image from C:// to folder etc..