c# - Unable to insert multiple imagepaths into single database row asp.net -
id upload files , insert filepaths database, unfortunately adds first record.
public actionresult create(list<httppostedfilebase> files, image img) { try { transportimages(files); int = 0; foreach (var x in imagepaths) { image _img = new image(); _img.img = imagepaths.elementat(i++); _pictures.images.add(_img); } if (i == imagepaths.count()) { _pictures.entry(img).state = entitystate.modified; _pictures.savechanges(); imagepaths.clear(); return view(); } return view(); }
here populate imagepaths list, later should inserted database.
private void transportimages(list<httppostedfilebase> images) { if (images.count() > 0) { foreach (httppostedfilebase img in images) { if (path.getfilename(img.filename) != null) { string pic = path.getfilename(img.filename); string path = system.io.path.combine( server.mappath("~/images"), pic); img.saveas(path); imagepaths.add("~/images/" + pic); } } }
Comments
Post a Comment