1

I use Bootstrap File Input in an ASP.NET MVC5 application as explained on Uploading a File (Or Files) With ASP.NET MVC.

View:

<input type="file" name="files" id="file1" >
<a href="javascript:;" id="file1Remove" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a>

<input type="file" name="files" id="file2" >
<a href="javascript:;" id="file2Remove" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a>

<input type="file" name="files" id="file3" >
<a href="javascript:;" id="file3Remove" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a>


Controller:

public ActionResult Insert([Bind(Exclude = null)] IEnumerable<HttpPostedFileBase> files)
{
    ...
}

I can post the images properly to the Controller via AJAX, however when I remove or change an image the other images are posted to the Controller null as shown below (in this scenario I selected 3 photos and then remove one of them before submitting form). Does anybody know how to fix it?

enter image description here

Jack
  • 1
  • 21
  • 118
  • 236
  • Not familiar with that plugin, but should the `data-dismiss` attribute in the `` have a relationship to the associated file input? –  Mar 17 '17 at 07:32
  • Not sure, but I also tried without data-dismiss using a click event for removing file. Actually the problem is that I cannot clear or reset the file input properly using many of approach i.e. [this](http://webtips.krajee.com/clear-html-file-input-value-ie-using-javascript/) and [this](http://stackoverflow.com/questions/16473227/bootstrap-clear-selected-file-using-jquery-data-dismiss). What do you think? – Jack Mar 17 '17 at 07:44
  • Don't have time to check the source code, but have you tried just wrapping each file input and its associated link inside a container (the second example in the link you gave - I assume it will then clear the file input within the container and not the others) –  Mar 17 '17 at 07:47
  • And as a side note, if you want a bit more flexibility, you might be interested in [this](https://github.com/stephenmuecke/mvc-filehelper) –  Mar 17 '17 at 07:49
  • Yes, I will wrap but for the first time I just wanted to test with the first one. However it does not clear file input. – Jack Mar 17 '17 at 07:53
  • But your code is not the same as in the linked examples :) –  Mar 17 '17 at 07:55
  • For your previous comment mvc-filehelper seems to be very nice but I need to image preview for all of the uploaded images. Is there another plugin you know that performs this requirements? Or shall I modify your plugin? – Jack Mar 17 '17 at 07:55
  • Yes, but the code posted here is just one version of my code (I modified many times). – Jack Mar 17 '17 at 07:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138302/discussion-between-stephen-muecke-and-clint-eastwood). –  Mar 17 '17 at 07:56
  • @StephenMuecke Could you please undelete your answer on https://stackoverflow.com/questions/46560515/how-to-create-dynamic-menu-using-tree – Jack Oct 10 '17 at 11:11

0 Answers0