【问题标题】:How to display a modal without using the onClick function如何在不使用 onClick 函数的情况下显示模式
【发布时间】:2020-01-16 13:35:45
【问题描述】:

我想知道如何在不单击按钮的情况下打开模式。基本上,如果用户搜索某些东西并且搜索没有返回结果,我希望弹出一个模式,通知用户搜索没有产生任何结果。我在下面粘贴了我的代码,但我认为我不应该从 html 中调用 jquery。

  <table id="tableData" class="table">
        <tr>
            <th>
                First Name
            </th>

            <th>
                Last Name
            </th>
            <th>
                MobileNumber
            </th>

            <th>
                EmailAddress
            </th>

            <th>
                Identification Number
            </th>

        </tr>

        @foreach (var item in Model)
        {

            if(Model.Count == 0)
            {
                 $('#myConfirmationModal').modal('show');

                //alert("no results find");
            }
            <tr>

                <td>

                    <a class="anchorDetail" href="javascript:;" data-id=@item.ClientId>@item.FirstName</a>
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MobileNumber)
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.EmailAddress)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.IdentificationNumber)
                </td>



            </tr>
        }

    </table>

【问题讨论】:

  • 在没有获取结果时使用对话框元素和打开属性!

标签: javascript jquery asp.net-mvc razor bootstrap-modal


【解决方案1】:

如果count0,则基本上需要在页面加载后执行$(#....).modal('show')。执行$(function(){...}) 中的代码。 JQuery 将确保在加载文档后执行$(...) 中的函数,即与$(document).ready(function(){...}) 相同

试试下面。

if(Model.Count == 0) {
     <script>
        $(function() {
            {
                 $('#myConfirmationModal').modal('show');

                //alert("no results find");
            }
        });
     </script>
} else {
     @foreach (var item in Model) {
     ...
     ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    相关资源
    最近更新 更多