foreach (var item in model) { using (html.beginform("previewimage", "music", formmethod.post, new { @enctype = "multipart/form-data" })) { @html.antiforgerytoken() <input type="file" class="upload-image" id="upload-image-file_@item.id" name="file" accept="image/*"> <button class="btn btn-default" id="bt_@item.id" style="display: none" type="submit"></button> } } how pass file id controller?
under assumption want pass path of image uploaded - inside of controller, use following:
if (request.files.count > 0) { var file = request.files[0]; if (file != null && file.contentlength > 0) { var filename = path.getfilename(file.filename); var serverpath = path.combine(server.mappath("~/images/"), filename); file.saveas(serverpath); } } under assumption talking @item.id variable appending id, add @item.id here:
using (html.beginform("previewimage", "music", formmethod.post, new { @enctype = "multipart/form-data", @itemid = @item.id })) and make corresponding changes controller.
Comments
Post a Comment