'How to use Saveas Method with Iformcollection in Asp.net MVC
Hello I am trying to upload Multiple Images but i am facing error i cannot use SaveAs with IFormcollection my code is work fine for single image but conflicting in multiple images. iformcollection does not contain a def for saveas What other method we can use with Iformcollection to upload Multiple Images
if (ModelState.IsValid)
{
product.Pro_Pic.SaveAs(Server.MapPath("~/ProductPicture/"+product.Pro_Pic.FileName));
product.Product_Picture = "~/ProductPicture/" +product.Pro_Pic.FileName;
foreach(var file in product.GalleryPic)
{
product.GalleryPic.SaveAs(Server.MapPath("~/ProductPicture/" + product.GalleryPic.FileName););
product.GalleryPic = "~/ProductPicture/" + product.Pro_Pic.FileName;
}
db.Products.Add(product);
db.SaveChanges();
return RedirectToAction("Index");
}
Here is my Model Code
[NotMapped]
public IFormCollection GalleryPic { get; set; }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
