如何在ASP.NET MVC中使用iformcollection使用saveas方法
您好,我正在尝试上传多个图像,但是我面临错误,我无法使用Iformcollection使用Saveas,我的代码在单张图像中工作正常,但在多个图像中矛盾。 不包含saveas的DEF
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");
}
iformcollection
[NotMapped]
public IFormCollection GalleryPic { get; set; }
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; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论