简体   繁体   中英

set partial view inside bootstrap modal window

I have partial view like

<div data-id="myModal" class="modal" tabindex="-1" role="dialog">
   ....
   some content
</div>

How can I on page load set this partial inside modal bootstrap window I tried with

$(document).ready(function () {
      $('#myModal').modal('show');
});

but that doesn't work

Change

<div data-id="myModal" class="modal" tabindex="-1" role="dialog">

to

<div id="myModal" class="modal" tabindex="-1" role="dialog">

To apply modal to html, first you must render html partial on page and then you can call your javascript like so:

@{Html.RenderPartial("~/Views/Shared/partial/myModal.cshtml");}

<script type="javascript">
    $(document).ready(function () {
      $('#myModal').modal('show');
    });
</script>

You may consider set a proper id for your modal id="myModal" instead of data-id="myModal" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM