-2

i use bootstrap modal in partialview not working, but working in view dont know what happen, anyone can help me, thanks! my code

@Html.Partial("_Header") (in layout)

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Modal title</h4>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#myModal').modal({
            backdrop: true,
            keyboard: false,
            show: false
        });
    });
</script>

http://s23.postimg.org/lfotq8xsb/image.jpg

tereško
  • 58,060
  • 25
  • 98
  • 150
Tam
  • 31
  • 1
  • 6
  • Can you expand on how it isn't working? Does the modal popup? Is it just not styled properly? Nobody will be able to successfully answer your question until we know more about the situation. – ethorn10 Sep 18 '13 at 03:33

1 Answers1

-3

Seems like there are another question quite similar. Check this question out and see if it helps you or not.

Using Bootstrap Modal window as PartialView

From your code, Seems like the you have your javascript in the partial view to trigger the modal form. But js in partial view will be ignore. You can check the source of the html.

So one of the solutions is put the js scripts in your layout or view instead in the partial view. Then it will work. That's the reason it work in layout or view and not in partial view.

Other Example : MVC4 partial view javascript bundling Issue

Community
  • 1
  • 1