首页 > 解决方案 > 触发没有按钮的模态

问题描述

我有一个非常基本的问题。我正在开发 .cshtml 格式的登录页面。现在我想在不使用按钮的情况下在引导程序中实现模式。就像登录凭据中的“条件错误”一样,然后显示模式。我给你下面的条件。从技术上讲,我看到很多带有按钮的引导程序,但我不希望那样。我希望模态自动执行。或模态的 HTML 部分在没有数据目标的情况下触发。

 @if (ViewContext.ModelState.IsValid == false)//condition for login failure, its in a file called _validation summary.cshtml

{
// Modal html we may change it.
    <div class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Modal title</h4>
                </div>
                <div class="modal-body">
                    <p>One fine body&hellip;</p>
                </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><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
}

提前感谢,杰伊

标签: htmlrazormodal-dialog

解决方案


您可以使用 JQuery 来调用模式,例如

    $('#modalId').modal("show");
    $('#modalId').modal("hide");
    $('#modalId').modal("toggle");

推荐阅读