Ajax调用后Razor下拉列表无法正常工作

时间:2018-10-30 02:16:52

标签: jquery jquery-ui razor bootstrap-4 asp.net-ajax

我实现了一个下拉菜单。第一次打开和关闭对话框时,下拉列表不起作用。但是,当我第二次打开和关闭对话框时,下拉菜单开始工作,依此类推。它交替工作。我曾经在ajax成功函数中重新启动下拉列表,但是它不起作用。

我附上了代码。请帮助我找出错误。

布局文件

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery-ui.min.css" rel="stylesheet" />
<link href="~/Content/jquery.dataTables.min.css" rel="stylesheet" />

<script src="~/Scripts/jquery-3.2.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
<script src="~/Scripts/datatables.min.js"></script>
<script src="~/Scripts/jquery.dataTables.min.js"></script>

<div class="dropdown pull-right" id="li_cent">
                    <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Welcome:@ViewBag.id
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu2" id="menue">
                        <li>@Html.ActionLink("Logout", "Logout", "MainPage")</li>

                    </ul>
 </div>

索引文件

<script>
            $(document).ready(function () {
                    $('.tablecontainer').on('click', 'a.popup', function (e) {

                        e.preventDefault();
                        OpenPopup($(this).attr('href'));

                    })

                    function OpenPopup(pageUrl) {
                        var $pageContent = $('<div/>');
                        $pageContent.load(pageUrl, function () {
                            $('#popupForm', $pageContent).removeData('validator');
                            $('#popupForm', $pageContent).removeData('unobtrusiveValidation');
                            $.validator.unobtrusive.parse('form');


                        });

                        $dialog = $('<div class="popupWindow" style="overflow:auto"></div>')
                            .html($pageContent)
                            .dialog({
                                draggable: true,
                                autoOpen: false,
                                resizable: true,
                                model: true,
                                title: 'Dialog',
                                height: 580,
                                width: 650,
                                close: function () {
                                    $dialog.dialog('destroy').remove();
                                }
                            })

                        $('.popupWindow').on('submit', '#popupForm', function (e) {
                            var url = $('#popupForm')[0].action;
                            //alert(url);
                            $.ajax({
                                type: "POST",
                                url: url,
                                data: $('#popupForm').serialize(),
                                success: function (data) {
                                    $dialog.dialog('close');
                                    oTable.ajax.reload();
                                    $('.dropdown-toggle').dropdown();
                                 }
                          })

                            e.preventDefault();
                        })

                        $dialog.dialog('open');

                    }
                })

    </script>

0 个答案:

没有答案