【发布时间】:2016-09-09 17:58:08
【问题描述】:
我正在引导模式中显示编辑表单。使用 asp mvc5,我将部分视图返回到引导模式窗口。表格显示出来,充满数据和帖子就好了。唯一的问题是不显示页眉和页脚。该代码显示在“查看页面源代码”中,但未显示在 Web 开发检查器 (chrome) 的元素选项卡中。
我计划在这一页上有多个不同的模式,所以我在 _layout 页面中为模式使用了一个占位符,然后传入不同的局部视图。
布局中的占位符:
<body>
@*Container for modal windows*@
<div class="modal fade" id="modal-container" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<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>×</span></button>
<h4 class="modal-title" id="modalLabel"></h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">This is the footer</div>
</div>
</div>
</div>
部分视图(仅包含一个表单和模态取消按钮):
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
<button class="btn btn-warning" data-dismiss="modal">Cancel</button>
</div>
</div>
一些js为链接添加“data-”标签:
$(function () {
$('body').on('click', '.modal-link', function(e) {
//e.preventDefault();
$(this).attr('data-target', "#modal-container");
$(this).attr('data-toggle', 'modal');
});
//Clear modal cache
$('#modal-container').on('hidden.bs.modal', function() {
$(this).removeData('bs.modal');
});
});
mvc 控制器只返回部分:
return PartialView("_EditOrchard", orchard);
【问题讨论】:
-
为什么不在部分响应中包含页眉和页脚。每个部分都会有不同的“保存”行为对吗?
-
好的,但我不明白为什么。我假设部分视图将被注入到“modal-body”div中,所以如果我将页眉和页脚放在部分视图中,它会将它们放在正文中。但事实并非如此。我猜是因为引导精灵正在构建整个模式并正确排序?
-
因为你的
modal-container是你有页眉和页脚的外部div。来自的响应将覆盖其现有内容。 -
这是有道理的。当我想象时,我一直认为它是在注入体内,但它是针对容器的。好,谢谢。输入一个答案,以便我标记它。
标签: asp.net-mvc twitter-bootstrap-3 bootstrap-modal