I am working on mvc. I have made an editing page where descriptions of a specific title are shown along with the multiple images added with a particular description. I want to make a button that adds one more image without removing the previously uploaded images. The new image should be added along with previously uploaded images.
I tried this from the controller side.
public ActionResult EditDescriptions(List<AddStoryDTO> model, HttpPostedFileBase[] Images)
{
if (model != null && ModelState.IsValid)
{
for (int i = 0; i < model.Count; i++)
{
var description = model[i];
var uploadedImages = Request.Files.GetMultiple($"Images_{i}");
List<string> imageNames = new List<string>();
if (uploadedImages != null && uploadedImages.Count > 0 && uploadedImages[0].ContentLength > 0)
{
foreach (var image in uploadedImages)
{
if (image != null && image.ContentLength > 0)
{
var imageName = Path.GetFileName(image.FileName);
var path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/StoryImage/"), imageName);
image.SaveAs(path);
imageNames.Add(imageName);
}
}
description.Imagename = string.Join(",", imageNames);
}
else
{
description.Imagename = model[i].Imagename;
}
bll.UpdateDescriptionAndImage(description);
}
return RedirectToAction("TitleList");
}
return View(model);
}
4