Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
281 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...