你好,我在 ASP.NET MVC4 应用程序中使用 Bootstrap v3.3.6 来使用模态视图显示弹出窗口。
我的模式示例:
<div class="modal-contents modal-view content-wrapper">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body content-wrapper">
</div>
</div>
<script type="text/javascript">
$(function () {
$('#approve-btn').click(function () {
$('#modal-container').modal('hide');
});
});
</script>
要加载模式,我使用 Html.ActionLink 之类的
@Html.ActionLink("SomeText", "SomeAction", "SomeController", null , new { @class="modal-link"})
这会在我的 _Layout 页面中触发我的脚本:
<script type="text/javascript">
$(function () {
// Initialize modal dialog
// attach modal-container bootstrap attributes to links with .modal-link class.
// when a link is clicked with these attributes, bootstrap will display the href content in a modal dialog.
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
console.log(this);
});
// Attach listener to .modal-close-btn's so that when the button is pressed the modal dialog disappears
$('body').on('click', '.modal-close-btn', function () {
$('#modal-container').modal('hide');
});
//clear modal cache, so that new content can be loaded
$('.modal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function () {
return false;
});
});
</script>
最后是我的 _Layout 中的占位符
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-content modal-view">
</div>
</div>
这一切都是基于这个设计的:http://www.codeproject.com/Tips/826002/Bootstrap-Modal-Dialog-Loading-Content-from-MVC-Pa并且工作得很好。直到我已经在同一 View 中打开一个模态后尝试打开一个模态。然后我会发现模态包含与以前相同的数据。
在尝试了所有建议之后:
Reload content in modal (twitter bootstrap)
我感觉问题出在#modal-container 的填充上。
链接由脚本以正确的方式完成,正如我可以通过在 chrome 中调试所说的那样。
如果我重新加载整个页面,模态视图将接受新内容。
但是因为我使用选项卡(也依赖于 Bootstrap )重新加载不是一个选项,因为我会丢失当前的选项卡选择。
我对网络开发还很陌生,所以如果你有一些想法就太好了。
最佳答案
你可以使用
ModelState.Clear();
用于清除 Controller 中的模型状态。
希望对你有帮助。
关于javascript - 模态视图重新加载内容(Bootstrap MVC ASP.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36601160/