无需按钮即可触发模态

时间:2018-08-06 09:26:34

标签: html razor modal-dialog

我有一个非常基本的问题。我正在开发.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 -->
}

预先感谢, 杰伊

1 个答案:

答案 0 :(得分:0)

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

    $('#modalId').modal("show");
    $('#modalId').modal("hide");
    $('#modalId').modal("toggle");
相关问题