我的模态表单成功发出 Ajax 请求。接收到的数据显示在后台。调用模式是通过 data-* 属性完成的,如 bootstrap 示例所示 here .但是模态并没有被解雇。我试着添加
OnSuccess = "$('#searchForm').modal('hide');"
到我的 Ajax.BeginForm。但这并不能消除模态在背景上转换的淡入淡出效果。
我的观点是:
<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>
我错过了什么吗?
请您参考如下方法:
在这种情况下,您正在打开 modal
通过 data-attributes
,然后使用 jQuery 关闭它。因此,在某种程度上,两种模态切换方法都被使用,它们相互冲突。因此,删除数据属性并显示/隐藏 modal
仅使用 jQuery。
尝试这个:
$('#searchForm').modal('show'); //for showing the modal
隐藏在 OnSuccess 上:
OnSuccess = "unloadModal"
功能
unloadModal
将会:
function unloadModal() {
$('#searchForm').modal('hide');
};