C# MVC5中的自举模型
我正试图在Bootstrap v3.3.5中打开一个模式对话框,但运气不好。单击我的链接时没有显示任何内容 对于我做错了什么,我真的非常感谢任何帮助 以下是C# MVC5中的自举模型,c#,asp.net-mvc,twitter-bootstrap,twitter-bootstrap-3,asp.net-mvc-5,C#,Asp.net Mvc,Twitter Bootstrap,Twitter Bootstrap 3,Asp.net Mvc 5,我正试图在Bootstrap v3.3.5中打开一个模式对话框,但运气不好。单击我的链接时没有显示任何内容 对于我做错了什么,我真的非常感谢任何帮助 以下是head部分中的脚本代码: $('body').on('click', '.modal-link', function (e) { e.preventDefault(); $(this).attr('data-target', '#modal-container'); $(this).at
head
部分中的脚本代码:
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
});
// 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-container').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function () {
return false;
});
这是分区:
<div id="modal-container" class="modal fade"
tabindex="-1" role="dialog">
<div class="modal-content">
</div>
</div>
最后,这是ActionLink在HomeController中调用的C#代码,它只是返回模态应显示的部分:
public ActionResult ViewApprovalModal() {
return PartialView("_ApprovalModal");
}
当我点击ActionLink时,什么也没有发生,在开发者控制台中也没有任何错误或任何其他警告,这就是为什么我如此困惑的原因。它什么都不做,没有错误。您需要进行服务器端调用吗?如果不是的话,我会摆脱它,做这个客户端
<button type="button" class="modal-link btn btn-success"
data-toggle="modal" data-target="#modal-container"
style="font-size: 17px;">
Approve Pending
</button>
@Html.Partial("_ApprovalModal")
批准待决
@Html.Partial(“_ApprovalModal”)
您的modal可能需要以下div:
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
除非您想编写自定义事件,否则您不需要任何额外的JavaScript。尝试将其包含在脚本中
<link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
然后尝试跟随Div
<div class="modal fade">
<div class="modal-dialog">
<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">Your title</h4>
</div>
<div class="modal-body">
<p>Your Body…</p>
</div>
</div>
</div>
</div>
&时代;
你的头衔
你的身体&hellip
您是否引用了引导javascript?绝对正确。整个页面呈现良好,全部使用引导和jQuery。除此之外,一切正常。当我点击ActionLink时,什么都没有发生,就像我说的,我没有收到任何错误。你能给我们看一下为按钮呈现的HTML吗?我在这里说得太快了。这个页面看起来像是有很好的引导功能,但这是因为CSS正在加载。由于路由配置中的一个小错误,它没有加载Bootstrap.js。它仍然不起作用,但这是朝着正确方向迈出的一步。@Html.RenderPartial(“\u ApprovalModal”)不会在不考虑单击的情况下呈现此部分吗?它没有附加任何要求。但只有单击按钮后,模式才会显示,因此在此之前它实际上是不可见的。由此我得到“编译器错误消息:CS1503:参数1:无法从“void”转换为“System.Web.WebPages.HelperResult”_ApprovalModal.cshtml是Views/Home文件夹中的一个有效部分,从控制器的角度来看,该文件夹是它的适当位置。我做错了什么@RenderPartial只需要一个字符串,我正在传递它。据我所知,这是一个有效的答案。对不起,我的意思是@Html.Partial(“_ApprovalModal”),我会编辑我的答案。
<div class="modal fade">
<div class="modal-dialog">
<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">Your title</h4>
</div>
<div class="modal-body">
<p>Your Body…</p>
</div>
</div>
</div>
</div>