1

Introduction: Hi, I'm new to Stackoverflow, any feedback apprichiated. I'm working on a larger mvc asp project and my problem concerns Views, modals and bootstrap. I created a website creating the necessary views, but was later asked to make some of these into modals, the easy solution was what follows.

Context: To open a modal I'm currently using:

  <a class="btn btn-default" href="@Url.Action("Edit", "Product", new { id = item.id})" data-toggle="modal" , data-target="#modal">open modal</a>

Which opens a my "Edit" View in/as a Modal.

(If you would like to see the modal or View, I can supply those, they are relativly standard though)

I used this method since it seemed to most logical to me at the time, I'm now wodering if it's the right choice.

Problem: complications arise when I want to close a secound modal (opend in the previous modal, the same way as before), the problem is that it closes all open modals.

<a href="#"  data-dismiss="modal" class="btn">Close</a>

I've tried using script functions to close the specific upper modal, without success.

Questions:

  1. Is the way I am currently handeling modals acceptable? (1. it works as long as you only want to open one modal)
  2. Is there an easy solution to close only one modal with my current setup?
  3. Is the problem related to bootstrap, if so, how do I solve it?

Related question/can be ignored: using this way of opening modals, i ran into the problem of "modal/View" content not resetting. Lets say I would give a product in my modal values and then close it, when I re-open it afterwards, the same values would still be shown, I "fixed" this using @Html.ActionLink instead of the traditional: <button type="button" class="close" data-dismiss="modal">&times;</button>

The problem here is that this forces a page refresh, which i would like to avoid.

I've tried variantions on the following, with no real success, I pressume because my modal is more View than modal.

  $(".modal").on("hidden.bs.modal", function(){
  $(".modal-content").html(""); 
});

Thanks for your time!

EDIT: So I found a solution to #2 I had placed my modals in two diffrent views, but to open multiples, i had to have them in the same View. Example: three views: Product, Edit and ProductDetails Edit modal was placed in Product, and ProductDetails modal was placed in Edit. Mistake was placing ProductDetails modal in Edit Once i placed all modals in Product it worked. I can now open and close modals, any way i want. But now my related problem is the main problem, the content doesn't reset uppon closing so the modal will show me the same information when selecting diffrent products

Patrick
  • 43
  • 8
  • Possible duplicate of [How to open two modal dialogs in Twitter Bootstrap at the same time](http://stackoverflow.com/questions/22713085/how-to-open-two-modal-dialogs-in-twitter-bootstrap-at-the-same-time) – kamil-mrzyglod Feb 20 '17 at 14:58
  • @Kamo, I don't think that post solves my problem, as far as i understand he was worried about being able to click on the first modal, while the secound modal is open. I'm worried, because my 'close' action on the secound modal closes both the secound, but also the first! – Patrick Feb 21 '17 at 08:25
  • Honestly even Bootstrap's documentation states, that multiple modals on the same page are not supported. The only way to make it work is to prepare a custom JS snippet and use ID property to distinguish modals. – kamil-mrzyglod Feb 21 '17 at 08:38
  • @Kamo could you share an example of this? sorry to bother you with this. – Patrick Feb 21 '17 at 09:12
  • Sorry but currently I don't have one to provide. – kamil-mrzyglod Feb 21 '17 at 10:58
  • So I found a solution to #2 I had placed my modals in two diffrent views, but to open multiples, i had to have them in the same View. Example: three views: Product, Edit and ProductDetails Edit modal was placed in Product, and ProductDetails modal was placed in Edit. Mistake was placing ProductDetails modal in Edit Once i placed all modals in Product it worked. I can now open and close modals, any way i want. But now my related problem is the main problem, the content doesn't reset uppon closing so the modal will show me the same information when selecting diffrent products – Patrick Feb 23 '17 at 10:50

0 Answers0