I want from a button to call a partial view using that has a modal using onClick for some reason it’s not working the function.
Let me know what I can change to make it work!.
Button
<a class="btn btn-outline-info mx-2 mx-sm-1" onclick="showModal()" id="nav-btn" ><i class="bi bi-upc-scan"></i></a>
Script
<script> function showModal() { $("#div1").load("/PurchaseOrder/Barcode", function () { $("#livestream_scanner").modal('toggle'); }); } </script>
Controller
public ActionResult Barcode() { return PartialView("~/Views/Barcode/SearchScanner.cshtml"); }
View with Modal
<div class="modal" id="livestream_scanner" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Search Barcode Scanner</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <div id="qr-reader" style="width:450px"></div> <div id="qr-reader-results" style="margin-bottom: 25px;"></div> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
Advertisement
Answer
Example:
<div class="modal" id="livestream_scanner" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Search Barcode Scanner</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body" id="modal-body"> <div id="qr-reader" style="width:450px"></div> <div id="qr-reader-results" style="margin-bottom: 25px;"></div> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
Then function
function showModal() { $.ajax({ url: "/PurchaseOrder/Barcode", dataType: 'html', beforeSend: function () { }, success: function (data) { $('#modal-body').html(data); $('#livestream_scanner').modal('show'); } }); }