Home > other >  Call Partial View with Modal using onClick in a button ASP.NET mvc
Call Partial View with Modal using onClick in a button ASP.NET mvc

Time:03-02

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  onclick="showModal()" id="nav-btn" ><i ></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  id="livestream_scanner" role="dialog">
    <div  role="document">
        <div >
            <div >
                <h5 >Search Barcode Scanner</h5>
                <button type="button"  data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div >
                <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 -->

CodePudding user response:

Example:

<div  id="livestream_scanner" role="dialog">
    <div  role="document">
        <div >
            <div >
                <h5 >Search Barcode Scanner</h5>
                <button type="button"  data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div  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');
        }
    });
}
  • Related