如何在ASP.NET MVC中使用iformcollection使用saveas方法

发布于 2025-01-27 21:54:46 字数 890 浏览 2 评论 0原文

您好,我正在尝试上传多个图像,但是我面临错误,我无法使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文