I have a Bootstrap modal dialog which contains a form. The modal dialog contains a submit and a cancel button. Now on submit
button click the form is submitted successfully but the modal dialog isn't getting closed. Here is my HTML:
<div class="modal fade" id="StudentModal" tabindex="-1" role="dialog" aria-labelledby="StudentModalLabel" aria-hidden="true" data-backdrop="static"> <div class="modal-dialog"> <div class="modal-content"> <form action="~/GetStudent" class="form-horizontal" role="form" method="post" id="frmStudent"> <div class="modal-footer"> <div class="pull-right"> <button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-ok"></i> Save</button> <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button> </div> </div> </form> </div> </div>
Anybody knows how to do this?
There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.
You CAN include a modal within a form. In the Bootstrap documentation it recommends the modal to be a "top level" element, but it still works within a form. You create a form, and then the modal "save" button will be a button of type="submit" to submit the form from within the modal.
If you want to prevent boostrap modal from closing by those actions, you need to change the value of backdrop and keyboard configuration. The default value of backdrop and keyboard is set to true . You can change the configuration in HTML or Javascript directly.
To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.
Use that Code
$('#button').submit(function(e) { e.preventDefault(); // Coding $('#IDModal').modal('toggle'); //or $('#IDModal').modal('hide'); return false; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With