Modal Popup is getting closing when am trying to append the data to its body in jquery
Modal Popup is getting closing when am trying to append the data to its body in jquery
Hi friends am trying to append a some data to my modal popup, which comes from the partial view on clicking some button, on clicking the Next button another question should be appended to the popup, and should not close it until user closes it manually, this is a simple test conducting application
@model List<Vulpith.Models.View.Test.AdaptabilityViewModel><div>
@foreach (var a in Model)
{
<div>@a.QDescription</div>
}
<button type="button" class="btn btn-default" onclick="StartTest()">Next</button>
am appending above content to the following model on ajax submission
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div id="appendquestion">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="StartTest()">Start Test</button>
</div>
</div>
</div>
following is the controller
public ActionResult _QuestionView()
{
return PartialView(new AdaptabilityTestTrans().Get());
}
and my ajax submission is
<script>
function StartTest() {
$.ajax({
url: $("baseUrl").html() + "Test/_QuestionView",
type: "POST",
success: function (data) {
debugger;
$('#appendquestion').html(data);
$('#myModal').modal(show);
},
error: function (data) {
$('#loading').hide();
}
});
}
data-dismiss="modal"
2 Answers
2
Remove data-dismiss="modal" from modal-footer. As you call StartTest()by clicking the Start Button, data-dismiss gets trigged and closes the modal.
data-dismiss="modal"
modal-footer
StartTest()
data-dismiss
<div class="modal-footer">
<button type="button" class="btn btn-default"onclick="StartTest()">Start Test</button>
</div>
Thank you sharma
– PTS PC
Jun 30 at 13:30
use jquery.noConflict() before $('#myModal').modal(show);
and run your code it will work
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Remove the
data-dismiss="modal"attribute (that closes you modal)– Stephen Muecke
Jun 30 at 13:05