如何显示 Bootstrap 对话框,然后调用 $.get 更新对话框代码

How to display a Bootstrap Dialog followed by calling $.get which updates the dialog code

我有一个 Bootstrap 对话框,其中有一个列表需要在交易发生后更新。我已将对话代码放在 MVC 局部视图中。我还定义了一个区域,其中局部视图将被渲染到父视图中,如下所示:

<div id="idCodeRefreshAreaForFindModal">
    @{Html.RenderPartial("_FindPurchaseOrderModal", Model); }
</div>

模态对话框显示正常,代码如下:

单击以显示对话框的按钮:

<input type="button" name="PurchaseOrderButton" value="Test with JavaScript function"
       class="btn btn-primary" id="idFindBtnTest2" />

jQuery 单击上述按钮时触发的事件处理程序:

$("#idFindBtnTest2").click(function () {
    $('#id-FindModal').modal('show');
  });  
});

但是,我需要的是在关闭并发生交易后刷新对话框代码。这是我遇到问题的地方。如果我更新上面的代码,以便 $.get 事务发生到 return,则稍后再次单击按钮将不会显示对话框的更新部分视图:

$("#idFindBtnTest2").click(function () {
    $('#id-FindModal').modal('show');

   var params = {};
   url = '@Url.Action("_FindPurchaseOrderModal", "PurchaseOrder")';
   $.get(url, $.param(params, false), function (data) {
       $('#idCodeRefreshAreaForFindModal').html(data); 
  });  
});

我认为对话框代码在显示之前正在更新,因此这破坏了对话框。如果我删除试图显示对话框的行并再次 运行 此测试, $.get 操作会成功更新模态的局部视图。如果我删除 $.get 部分并只保留显示对话框部分,那么对话框会正常显示。

我尝试在语句后添加 sleep(2000) 语句来显示对话框,但这不起作用。对话框关闭后,如何执行 $.get 以使用局部视图更新对话框代码?

How can I perform a $.get to update the dialog code with the partial view after the dialog closes?

这可能是更好的解决方案,而不是将事件绑定到显示模态的按钮,您可以在模态关闭时绑定事件

Bind a function to Twitter Bootstrap Modal Close

$("#idFindBtnTest2").click(function () {
    $('#id-FindModal').modal('show');
});

$(document).on('hidden.bs.modal', '#id-FindModal', function (event) {
   var params = {};
   url = '@Url.Action("_FindPurchaseOrderModal", "PurchaseOrder")';
   $.get(url, $.param(params, false), function (data) {
       $('#idCodeRefreshAreaForFindModal').html(data); 
   }); 
});