模式视图重新加载内容(启动MVC ASP.NET)
Modal View Reload Content (Bootstrap MVC ASP.NET)
Aloha,我在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"})
它触发了我的布局页面中的脚本:
<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工作得很好。直到我在同一个视图中打开了一个模态之后尝试打开一个模态。然后我会发现模态包含与以前相同的数据
在尝试了以下所有建议后:
在模态中重新加载内容(twitter引导程序)
我感觉问题出在#modal容器的填充上。链接是由脚本以正确的方式完成的,正如我可以说的那样,通过在chrome中调试
如果我重新加载整个页面,模式视图将接受新内容。但由于我使用选项卡(也依赖于Bootstrap),重新加载不是一个选项,因为我会失去当前选项卡的选择。
我对网络开发很陌生,所以如果你有一些想法的话,那就太好了。
您可以使用
ModelState.Clear();
用于清除控制器中的模型状态。
希望它能帮助你。
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- Meteor上的启动页面
- 将Javascript数组发送到控制器ASP.NET MVC
- 如何防止网页加载后自动启动功能
- 如何使用Spring MVC将Facebook返回的响应数据保存在Java类中
- 如何在MVC中使用jQuery在文本框旁边显示文本
- MVC 3页面导航和使用javascript传递参数
- 在mvc应用程序中,在回发时保留最初隐藏的文本框的隐藏或可见状态
- 如何从JavaScriptInterface启动Navigation Drawer
- 模式视图重新加载内容(启动MVC ASP.NET)
- 验证启动但不启动't显示故障信息.我错过了什么?MVC 5 Razor
- 在应用程序启动时生成路由 URL 列表,并插入到 MVC 中的 javascript 文件中
- MVC Razor-onClick在页面加载时未启动
- ASP.NET MVC Javascript在页面加载时未首次启动
- 如何同时启动客户端和MVC验证
- MVC DropDownList选择已更改,未启动Ajax
- mvc 5在回发后启动javascript定时器