Javascript 模式视图重新加载内容(引导MVC ASP.NET)
阿罗哈,我正在ASP.NET MVC4应用程序中使用Bootstrap v3.3.6来使用模式视图显示弹出窗口 我的模式示例:Javascript 模式视图重新加载内容(引导MVC ASP.NET),javascript,asp.net,asp.net-mvc,twitter-bootstrap,Javascript,Asp.net,Asp.net Mvc,Twitter Bootstrap,阿罗哈,我正在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">×
<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>
在我的布局页面中触发我的脚本:
<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>
$(函数(){
//初始化模态对话框
//将模态容器引导属性附加到具有.modal链接类的链接。
//当使用这些属性单击链接时,引导将在模式对话框中显示href内容。
$('body')。在('click','modal link',函数(e)上{
e、 预防默认值();
$(this.attr('data-target','#modal container');
$(this.attr('data-toggle','modal');
console.log(this);
});
//将侦听器连接到.modal关闭btn,以便当按下按钮时,模态对话框消失
$('body')。在('click','上。模式关闭btn',函数(){
$(“#模态容器”).modal('hide');
});
//清除模式缓存,以便可以加载新内容
$('.modal').on('hidden.bs.modal',function(){
$(this.removeData('bs.modal');
});
$('#cancelmodel')。在('click',函数(){
返回false;
});
});
最后是my_布局中的占位符
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-content modal-view">
</div>
</div>
这一切都是基于这个设计的:并且工作得很好。直到我在同一个视图中打开一个模式后尝试打开一个模式。然后我会发现模态包含与前面相同的数据尝试以下所有建议后:
我有种感觉,问题在于“莫代尔”集装箱的重新装满。 这些链接由脚本以正确的方式完成,正如我在chrome中调试时所说的那样
如果重新加载整个页面,模态视图将接受新内容。 但是,由于我使用标签(也依赖于引导),重新加载不是一个选项,因为我会失去当前的标签选择 我对网络开发非常陌生,如果你有一些想法,那就太好了。你可以使用
ModelState.Clear();
以清除控制器中的模型状态
希望它能对您有所帮助。您试图用相同的模式打开模式,但不同的内容已经打开,这是什么情况?这是一个有点不寻常的场景。可能的重复:我描述得很糟糕。我想从父视图中关闭模式并用另一个链接(和数据)重新打开它。我正在显示Webgrid并尝试显示不同的详细信息。对于你提到的问题,我已经尝试了最多的解决方案。但是我会找一些备用的。不,伙计,这是模型。他的问题与模型状态无关。他的问题是关于boostrap情态动词的行为。
ModelState.Clear();