asp.net - 无限循环foreach

时间:2017-05-30 15:22:49

标签: c# asp.net file file-upload foreach

foreach (HttpPostedFile file in filePhotos.PostedFiles)
{
    RandomStringGenerator rnd = new RandomStringGenerator();
    string filename = rnd.Generate(5) + Path.GetExtension(file.FileName);
    file.SaveAs(Server.MapPath("~/Content/Photos/") + filename);
    Sweet_Shailene___EN.Photo p = new Sweet_Shailene___EN.Photo();
    p.GalleryId = Convert.ToInt32(drpGallery.SelectedValue);
    p.Url = filename;
    db.Photos.Add(p);
    db.SaveChanges();
}

它已经无限循环了!任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

最后感谢Varun我把

db.saveChanges();

在foreach之外