Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

jquery - Bootstrap Modal not working in partialview

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...