问题描述
我的模式表单成功发出了Ajax请求.接收到的数据显示在背景中.引导模式是通过data- *属性完成的,引导示例显示了此处.但是模态并没有被解雇.我试图添加
My modal form successfully makes an Ajax request. The data received is displayed in the background. Invoking the modal is done by data-* attributes as bootstrap examples show here. But the modal is not getting dismissed. I tried to add
OnSuccess = "$('#searchForm').modal('hide');"
到我的Ajax.BeginForm.但这并不能消除模态投射在背景上的淡入效果.
to my Ajax.BeginForm. But this doesn't remove the fade effect that modal cast on the background.
我的看法是:
<div class="modal fade" id="searchForm" tabindex="-1" role="dialog" aria-labelledby="searchFormLabel">
<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">×</span></button>
<h4 class="modal-title" id="searchFormLabel">Search Here</h4>
</div>
<div class="modal-body">
@using (Ajax.BeginForm(new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "results",
OnSuccess = "$('#searchForm').modal('hide');"
}))
{
// input fields and submit button are here
}
</div>
</div>
</div>
</div>
我想念什么吗?
推荐答案
在这种情况下,您要通过data-attributes
打开modal
,然后使用jQuery将其关闭.因此,以某种方式使用了两种模态切换方法,它们彼此冲突.因此,删除数据属性并仅使用jQuery显示/隐藏modal
.
In this case, you are opening up the modal
via data-attributes
, and then closing it using jQuery. So, in a way both modal toggling methods are used, which are conflicting with each other. So, remove the data-attributes and show/hide the modal
using jQuery only.
尝试一下:
$('#searchForm').modal('show'); //for showing the modal
要隐藏在OnSuccess上:
For hiding on OnSuccess:
OnSuccess = "unloadModal"
功能unloadModal
将是:
function unloadModal() {
$('#searchForm').modal('hide');
};
这篇关于成功的Ajax请求后关闭Bootstrap Modal表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!